這篇文章主要介紹怎么用CSS和GSAP實(shí)現(xiàn)樹(shù)枝發(fā)芽的loader動(dòng)畫(huà),文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
為淳安等地區(qū)用戶提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及淳安網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)、淳安網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
代碼解讀
定義dom,容器包含2個(gè)元素,branch代表枝,leaves代表葉,葉有6個(gè)子元素,代表6個(gè)葉片:
<figureclass="sapling">
<divclass="branch"></div>
<divclass="leaves">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</figure>
居中顯示:
body{
margin:0;
height:100vh;
display:flex;
align-items:center;
justify-content:center;
background-color:black;
}
定義容器尺寸,并設(shè)置子元素水平居中:
.sapling{
position:relative;
width:5em;
height:17.5em;
font-size:10px;
display:flex;
justify-content:center;
}
畫(huà)出樹(shù)枝:
.branch{
position:absolute;
width:0.2em;
height:inherit;
border-radius:25%;
background:burlywood;
}
定義樹(shù)葉容器,設(shè)置為葉片在垂直方向均勻分布,并且從下到上排列:
.leaves{
position:absolute;
width:inherit;
height:15em;
top:1em;
display:flex;
flex-direction:column-reverse;
}
設(shè)置葉片的尺寸和和背景顏色:
.leavesspan{
width:2.5em;
height:2.5em;
background-color:limegreen;
}
設(shè)置左右葉片的各自樣式:
.leavesspan:nth-child(odd){
border-bottom-left-radius:3em;
border-top-right-radius:3em;
transform-origin:rightbottom;
align-self:flex-start;
}
.leavesspan:nth-child(even){
border-bottom-right-radius:3em;
border-top-left-radius:3em;
transform-origin:leftbottom;
align-self:flex-end;
}
至此,靜態(tài)效果繪制完成,接下來(lái)開(kāi)始寫(xiě)動(dòng)畫(huà)腳本。
引入GSAP庫(kù):
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/TweenMax.min.js"></script>
聲明一個(gè)時(shí)間線對(duì)象:
letanimation=newTimelineMax();
增加樹(shù)枝的入場(chǎng)動(dòng)畫(huà)效果,并為這個(gè)動(dòng)畫(huà)設(shè)置一個(gè)標(biāo)簽branch:
animation.from('.branch',4,{scaleY:0,ease:Power1.easeOut},'branch');
增加樹(shù)葉的入場(chǎng)動(dòng)畫(huà)效果,它的參數(shù)中有3個(gè)0.5,從左到右的含義分別是動(dòng)畫(huà)時(shí)長(zhǎng)、多個(gè)葉片動(dòng)畫(huà)的間隔時(shí)長(zhǎng)、相對(duì)branch標(biāo)簽動(dòng)畫(huà)的延遲時(shí)間:
animation.from('.branch',4,{scaleY:0,ease:Power1.easeOut},'branch')
.staggerFrom('.leavesspan',0.5,{scale:0,ease:Power1.easeOut},0.5,0.5,'branch');
增加葉片變黃的動(dòng)畫(huà)效果:
animation.from('.branch',4,{scaleY:0,ease:Power1.easeOut},'branch')
.staggerFrom('.leavesspan',0.5,{scale:0,ease:Power1.easeOut},0.5,0.5,'branch')
.to(['.branch','.leavesspan'],3,{backgroundColor:'yellow'});
增加淡出效果:
animation.from('.branch',4,{scaleY:0,ease:Power1.easeOut},'branch')
.staggerFrom('.leavesspan',0.5,{scale:0,ease:Power1.easeOut},0.5,0.5,'branch')
.to(['.branch','.leavesspan'],3,{backgroundColor:'yellow'})
.to(['.branch','.leavesspan'],1,{autoAlpha:0});
修改聲明時(shí)間線的代碼,使動(dòng)畫(huà)重復(fù)播放:
letanimation=newTimelineMax({repeat:-1,repeatDelay:0.5});
大功告成!
以上是“怎么用CSS和GSAP實(shí)現(xiàn)樹(shù)枝發(fā)芽的loader動(dòng)畫(huà)”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
文章標(biāo)題:怎么用CSS和GSAP實(shí)現(xiàn)樹(shù)枝發(fā)芽的loader動(dòng)畫(huà)
網(wǎng)頁(yè)URL:http://jinyejixie.com/article16/gciogg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、小程序開(kāi)發(fā)、云服務(wù)器、網(wǎng)站建設(shè)、App設(shè)計(jì)、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)