css 呼吸燈效果


 

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
  *{
margin:0;
padding:0;
border:0;
}
.wrap{
width: 800px;
height: 600px;
position: relative;
margin: 0 auto;
overflow: hidden;
}
.img1,.img2{
width: 1920px;
position: absolute;
left: 50%;
margin-left: -1360px;
}
.img2{
animation: breath 3s infinite ease-in-out alternate;
}

@keyframes breath {
0% {opacity: .2;}70% {opacity: 1;}to {opacity: .2;}
}
    </style>
</head>

<body>
    <div class="wrap">
        <img src="https://img.alicdn.com/tfs/TB15mxgIxSYBuNjSspjXXX73VXa-3840-1280.jpg" alt="呼吸底燈" class="img1">
        <img src="https://img.alicdn.com/tfs/TB1i8oWIbGYBuNjy0FoXXciBFXa-3840-1280.png" alt="呼吸燈" class="img2">
        </div>


    <script>


    </script>

</body>

</html>
 
PS:
 

最常用的幾種屬性有以下幾種:

1、animation-name(動畫名稱)

 animation-name屬性是必須存在的,因為animation-name的值默認是none,沒有動畫。

2、animation-duration(動畫執行一次所需時間)

 animation-duration屬性也是必須存在的,因為animation-duration的值默認是0,沒有動畫。

3、animation-delay(動畫在開始前的延遲時間)

 animation-delay的值可以是秒(s)或者是毫秒(ms),默認值是0,沒有延遲。

4、animation-timing-function(動畫以何種運行軌跡完成一個周期)

  animation-timing-function的值是貝塞爾曲線,默認值是ease,表示動畫以低速開始,然后加速,最后在結束前變慢。 最常用的值有以下幾個:

(1)linear:表示動畫從頭到尾的速度都是相同的。

(2)ease-in:表示動畫以低速開始。

(3)ease-out:表示動畫以低速結束。

(4)ease-in-out:表示動畫以低速開始和結束。

如果沒有想用的值,也可以直接使用三次貝塞爾函數,使用網站是http://cubic-bezier.com,可直接調試出自己想要的值;也可以在瀏覽器中直接調試,現在瀏覽器調試工具中都支持貝塞爾函數可視化調試。

5、animation-iteration-count(動畫播放次數)

 animation-iteration-count屬性值有兩種:

(1)直接寫數字,自定義想要播放動畫的次數。

(2)infinite:設置動畫無線循環播放。

6、animation-fill-mode(定義元素動畫結束以后或者未開始的元素樣式) 

 默認值為none,標示,不會在動畫結束或者未開始時給元素 添加樣式 

 常用屬性值為:

(1)forwards:表示動畫結束后,元素直接接使用當前樣式。

(2)backwards:表示在動畫延遲時間元素使用關鍵幀中from的屬性值或者to屬性值(當animation-direction為reverse或者alternate-reverse時)   

7、animation-direction(是否輪流反向播放動畫)

 默認值是normal,動畫正常播放。如果動畫只播放一次,則該屬性無效。

 常用的屬性值為:

(1)reverse:表示動畫反向播放。

(2)alternate:表示動畫在奇數次播放時為正向播放,為偶數次播放時為反向播放。

(3)alternate-reverse: :表示動畫在奇數次播放時為反向播放,為偶數次播放時為正向播放。              

animation屬性在書寫通常合並在一起,除非需要單獨設置的屬性值,animation屬性的簡寫形式為:animation:code 2s 2s linear  infinite alternate forwards;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM