css小動畫(大小變換 、水波紋、loading)

一、無限放大縮小
可以應(yīng)用于跳動的氣球等場景,效果如下:

html部分

<div class="ballon"></div>

css部分

   @keyframes scaleDraw {  /*定義關(guān)鍵幀、scaleDrew是需要綁定到選擇器的關(guān)鍵幀名稱*/
            0%{
                transform: scale(1);  /*開始為原始大小*/
            }
            25%{
                transform: scale(1.1); /*放大1.1倍*/
            }
            50%{
                transform: scale(1);
            }
            75%{
                transform: scale(1.1);
            }
        }
    .ballon{
            width: 150px;
            height: 200px;
            background: url("images/balloon.png");
            background-size: 150px 200px;
            -webkit-animation-name: scaleDraw; /*關(guān)鍵幀名稱*/
            -webkit-animation-timing-function: ease-in-out; /*動畫的速度曲線*/
            -webkit-animation-iteration-count: infinite;  /*動畫播放的次數(shù)*/
            -webkit-animation-duration: 5s; /*動畫所花費(fèi)的時間*/
            /*-webkit-animation: scaleDraw 5s ease-in-out infinite;/*![20180205175321080.gif](https://upload-images.jianshu.io/upload_images/7513201-f94b4dbc1ebecde9.gif?imageMogr2/auto-orient/strip)

        }



或者是一起控制透明度和大小的變換,如圖

html部分

<button class="button"></button>

css部分

<style type="text/css">
        .button{
            margin: 100px;
            width: 30px;
            height:30px;
            background: orange;
            border-radius: 50px;
            animation: flipping 5s infinite;

            /*去除button默認(rèn)邊框*/
            background-position-x: -7px;
            background-position-y: -7px;
            border: 1px;
            outline: none;
        }

        @keyframes flipping{
        0%{
            opacity: .2;
            transform: scale(1);
        }
        25%{
            opacity: 1;
            box-shadow:  0 0 15px orange;
            transform: scale(1.4);
        }
        50%{
            opacity: .2;
            transform: scale(1);
        }
        75%{
            opacity: 1;
            box-shadow:  0 0 15px orange;
            transform: scale(1.4);
        }
        100%{
            opacity: .2;
            transform: scale(1);
        }
    }
    </style>



二、漣漪擴(kuò)散

實(shí)質(zhì)就是就是利用了動畫的延遲屬性,兩層圓的動畫相關(guān)的屬性基本相同,除了最外層的圓多設(shè)置了animation-delay屬性

html部分

 <div class="live">
         <img src="images/live.png" alt="">
         <span></span>
         <span></span>
     </div>

css部分

.live{
           position: relative;
           width: 100px;
           height: 100px;
       }
       .live img{
           width: 100px;
           height: 100px;
           z-index: 0;
       }
        @keyframes living {
            0%{
                transform: scale(1);
                opacity: 0.5;  
            }
            50%{
                transform: scale(1.5);  
                opacity: 0;   /*圓形放大的同時,透明度逐漸減小為0*/
            }
            100%{
                transform: scale(1);
                opacity: 0.5;
            }
        }
        .live span{
            position: absolute;
            width: 100px;
            height: 100px;
            left: 0;
            bottom: 0;
            background: #fff;
            border-radius: 50%;
            -webkit-animation: living 3s linear infinite;
            z-index: -1;
        }
        .live span:nth-child(2){
            -webkit-animation-delay: 1.5s; /*第二個span動畫延遲1.5秒*/
        }





三、雷達(dá)


html部分

<div class="container">
    <div class="dot"></div>
    <div class="pulse p1"></div>
    <div class="pulse p2"></div>
</div>

css部分

.container {
position: relative;
}

.dot {
position: absolute;
width: 10px;
height: 10px;
left: 160px;
top: 160px;
border-radius: 50%;
border: 1px solid #33ccff;
background-color: #33ccff;
}

.pulse {
position: absolute;
width: 88px;
height: 88px;
left: 120px;
top: 120px;
border: 2px solid #3399ff;
border-radius: 50%;
opacity: 0; 
}

.p1 {
animation: warn 2s ease-out infinite;
}
.p2 {
animation: warn2 2s ease-out infinite;
}
/*.p1 {
animation: warn 2s ease-out infinite;
}
.p2 {
animation: warn 2s ease-out infinite;
-webkit-animation-delay: 1.5s;
}*/

@keyframes warn {
0% {transform: scale(0.3);opacity: 0.0;}

25% {transform: scale(0.3);opacity: 0.1;}

50% {transform: scale(0.5);opacity: 0.3;}

75% {transform: scale(0.8);opacity: 0.5;}

100% {transform: scale(1);opacity: 0.0;}
}

@keyframes warn2 {
0% {transform: scale(0.3);opacity: 0.0;}

25% {transform: scale(0.3);opacity: 0.1;}

50% {transform: scale(0.3);opacity: 0.3;}

75% {transform: scale(0.5);opacity: 0.5;}

100% {transform: scale(0.8);opacity: 0.0;}
}





四、加載loading


loading.png

實(shí)質(zhì)就是讓包裹loading.png圖片的元素360度循環(huán)的轉(zhuǎn)動。
html部分

<div class="loading">
    <img src="./loading.png">
</div>

css部分

.loading{
  width: 80px;
  height: 80px;
  animation: spin 1.2s linear infinite;
}
.loading img{
    width:100%;
    height:100%;
}
@keyframes spin
{
  0%   {transform: rotate(0deg);}
  100% {transform: rotate(360deg);}
}

也可用字體圖標(biāo)來代替圖片。




更多l(xiāng)oading小動畫參見純CSS3加載Loading動畫圖 12款創(chuàng)意設(shè)計(jì)

5f8cw-u3geg.gif



參考文章:
CSS3 動畫實(shí)現(xiàn)放大縮小、漣漪擴(kuò)散效果、疊加圖片循環(huán)來回顯示

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一、HTML 教程 HTML教程HTML簡介HTML編輯器HTML基礎(chǔ)HTML元素HTML屬性 HTML標(biāo)題HTM...
    茶茶點(diǎn)閱讀 937評論 0 0
  • CSS參考手冊 一、初識CSS3 1.1 CSS是什么 CSS3在CSS2.1的基礎(chǔ)上增加了很多強(qiáng)大的新功能。目前...
    沒汁帥閱讀 4,280評論 1 13
  • 選擇qi:是表達(dá)式 標(biāo)簽選擇器 類選擇器 屬性選擇器 繼承屬性: color,font,text-align,li...
    love2013閱讀 2,437評論 0 11
  • 由于周四要去培訓(xùn)學(xué)習(xí),今天我們就進(jìn)行了學(xué)月考試??纪旰笪覀儙讉€老師就在辦公室改完了卷子,統(tǒng)計(jì)好了分?jǐn)?shù)??吹揭?..
    十月的抄手閱讀 134評論 0 0
  • 小小的記錄一下,破1000鉆的開心一刻。 買會員簡書送了700鉆,原始積分兌換了100鉆左右,其余的就是日更50多...
    張習(xí)瑤閱讀 396評論 0 2

友情鏈接更多精彩內(nèi)容