微信小程序?qū)崿F(xiàn)自定義加載圖標(biāo)功能
效果圖

實現(xiàn)思路
1.首先通過HTML+CSS實現(xiàn)加載動畫的靜態(tài)效果;
2.根據(jù)需求給每個動畫設(shè)計不同的動畫效果。
例如第一個加載圖標(biāo)的靜態(tài)繪制
1、首先確定動畫的盒子寬高;
2、設(shè)置盒子中每一個長方形的寬高以及定位(注意:此處需要將長方形的旋轉(zhuǎn)中心點移動到長方形的右側(cè)邊終點,方便后期以該點旋轉(zhuǎn)。);
3、通過長方形盒子的偽元素,設(shè)置顯示的長方形背景和寬高,同時進(jìn)行定位。
4、由于在第二步的時候,已經(jīng)將旋轉(zhuǎn)中心移動,此處我們直接對每一個盒子中長方形進(jìn)行旋轉(zhuǎn)(注意:旋轉(zhuǎn)角度 = 360 / 盒子中長方形個數(shù))。
.circle-line{
width: 100px;
height: 100px;
display: inline-block;
position: relative;
}
.circle-line text{
display: block;
width: 50%;
height: 5px;
opacity: .7;
position: absolute;
top: calc(50% - 2.5px);
left: 0px;
transform-origin: center right;
}
.circle-line text::before{
content: '';
display: block;
width: 15px;
height: 5px;
position: absolute;
top: 0;
right: 10px;
background-color: blue;
}
.circle-line text:nth-child(1){
transform: rotate(0deg);
}
.circle-line text:nth-child(2){
transform: rotate(45deg);
}
.circle-line text:nth-child(3){
transform: rotate(90deg);
}
.circle-line text:nth-child(4){
transform: rotate(135deg);
}
.circle-line text:nth-child(5){
transform: rotate(180deg);
}
.circle-line text:nth-child(6){
transform: rotate(225deg);
}
.circle-line text:nth-child(7){
transform: rotate(270deg);
}
.circle-line text:nth-child(8){
transform: rotate(315deg);
}
動畫制作
觀察發(fā)現(xiàn)動畫只是針對每個長方形的透明度進(jìn)行改變,所以動畫采用從0.05到0.9的透明度循環(huán)改變。
@keyframes circle {
0%{
opacity: 0.05;
}
100%{
opacity: 0.9;
}
}
進(jìn)行動畫綁定
.circle-line text{
animation: circle 1.5s linear infinite;
}
動畫綁定完成,發(fā)現(xiàn)所有的整個圖標(biāo)一起顯示消失,那么也就是缺少了對單個個體的動畫處理,延遲動畫時間,使其依次漸變。
單個動畫處理
.circle-line text:nth-child(1){
animation-delay: 0.2s;
}
.circle-line text:nth-child(2){
animation-delay: 0.4s;
}
.circle-line text:nth-child(3){
animation-delay: 0.6s;
}
.circle-line text:nth-child(4){
animation-delay: 0.8s;
}
.circle-line text:nth-child(5){
animation-delay: 1s;
}
.circle-line text:nth-child(6){
animation-delay: 1.2s;
}
.circle-line text:nth-child(7){
animation-delay: 1.4s;
}
.circle-line text:nth-child(8){
animation-delay: 1.6s;
}
注意:單個動畫延遲的時間必須超過動畫執(zhí)行的總時間,防止一個動畫執(zhí)行完成后的卡頓。
總結(jié)
以上所述是小編給大家介紹的微信小程序?qū)崿F(xiàn)自定義加載圖標(biāo)功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
服務(wù)端渲染nextjs項目接入經(jīng)驗總結(jié)分析
這篇文章主要為大家介紹了服務(wù)端渲染nextjs項目接入經(jīng)驗總結(jié)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11
JavaScript實現(xiàn)頁面5秒后自動跳轉(zhuǎn)的方法
這篇文章主要介紹了JavaScript實現(xiàn)頁面5秒后自動跳轉(zhuǎn)的方法,涉及javascript遞歸調(diào)用與計時函數(shù)setTimeout的使用技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04

