CSS3 波浪簡單類比--我是波浪,我有起伏,有大波與小波(壞笑中...),
我是波浪,我有起伏,我有大波與小波(壞笑中...)
最近改版網站,一般也不會去寫動畫,但是有些網站還是需要的,故拿出一個較簡單的動畫出來分享,很簡單很簡單。
原理簡單闡述
其實很簡單,使用一張美工做好了的2400px寬度的3個不同起伏的波浪,然後自己合成為一張【精靈圖片】(有助於一起加速載入和同時載入)
有了素材就好辦了,使用一個容器把3個div背景的波浪堆在一起,然後使用css3的位移進行移動,當然左右和上下都要,然後慢慢調整為一個適合的時間和延遲。
廢話不多說,先上示範地址:http://sandbox.runjs.cn/show/akodn0vt
波浪動畫CSS
<style type="text/css"> /* * author: jasnature * email : 276227015@qq.com * last update : 2016-04-21 * */ .index_waves { background: url("img/index_waves.png 這裡放波浪圖,圖可以去示範地址摳出來") center 0 no-repeat; } .wave3 { height: 427px; width: 2402px; background-position: 0 0; } .wave2 { height: 427px; width: 2402px; background-position: 0 -427px; } .wave1 { height: 427px; width: 2402px; background-position: 0 -854px; } @keyframes wave { 0% { transform: translate(0px, 0px); } 50% { transform: translate(-80px, 30px); } 100% { transform: translate(160px, -60px); } } @-webkit-keyframes wave { 0% { transform: translate(0px, 0px); } 50% { transform: translate(-80px, 30px); } 100% { transform: translate(160px, -60px); } } @-moz-keyframes wave { 0% { transform: translate(0px, 0px); } 50% { transform: translate(-80px, 30px); } 100% { transform: translate(160px, -60px); } } .waves { position: absolute; bottom: -135px; height: 527px; width: 100%; overflow: hidden; } .waves > div { position: absolute; left: -180px; bottom: 0; } .waves .wave1, .waves .wave2, .waves .wave3 { animation: wave 5s ease-in-out alternate infinite; } .waves .wave2 { animation-delay: 0.6s; } .waves .wave3 { animation-delay: 1.2s; } .waveContent { position: relative; background-color: #219df3; height: 500px; } h2 { position: relative; display: block; color: #fff; font-size: 48px; font-family: "microsoft yahei"; font-weight: normal; width: 1100px; margin: 0 auto; top: 180px; z-index: 99; } </style>
波浪動畫HTML
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>我是波浪,我有起伏,我有大波與小波(壞笑中...)</title> </head> <body> <div class="waveContent"> <h2>我是波浪,我有起伏,我有大波與小波(壞笑中...)</h2> <div class="waves"> <div class="index_waves wave1"> </div> <div class="index_waves wave2"> </div> <div class="index_waves wave3"> </div> </div> </div> </body></html>
好咯,代碼附送完畢。