首頁  >  文章  >  web前端  >  css怎麼實現圖片放大縮小動畫

css怎麼實現圖片放大縮小動畫

青灯夜游
青灯夜游原創
2022-01-20 15:37:2420378瀏覽

方法:1、使用「@keyframes 動畫名稱{}」規則和「transform:scale(縮放比例);」語句建立放大縮小動畫;2、使用「圖片元素{animation:動畫名稱時間infinite ;}」語句縮放動畫套用於圖片元素。

css怎麼實現圖片放大縮小動畫

本教學操作環境:windows7系統、CSS3&&HTML5版、Dell G3電腦。

在css中,可以使用animation屬性、「@keyframes」規則、transform: scale()實作圖片放大縮小動畫。

範例1:

<div class="ballon"></div>
/*css部分*/
   @keyframes scaleDraw {  /*定义关键帧、scaleDrew是需要绑定到选择器的关键帧名称*/
            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; /*关键帧名称*/
            -webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/
            -webkit-animation-iteration-count: infinite;  /*动画播放的次数*/
            -webkit-animation-duration: 5s; /*动画所花费的时间*/
        }

上面的幾個屬性也可以合在一起寫

animation: scaleDraw 5s ease-in-out infinite;
-webkit-animation: scaleDraw 5s ease-in-out infinite;

效果:

css怎麼實現圖片放大縮小動畫

實例2:

 <div class="live">
         <img src="images/live.png" alt="">
         <span></span>
         <span></span>
 </div>
.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秒*/
        }

css怎麼實現圖片放大縮小動畫

#實質就是利用了動畫的延遲屬性,兩層圓的動畫相關的屬性基本上相同,除了最外層的圓多設定了animation-delay屬性

(學習影片分享:css影片教學

以上是css怎麼實現圖片放大縮小動畫的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn