純css制作聲波擴(kuò)散動畫

在制作音樂播放器時(shí)需要哪種在播放音樂時(shí)音樂的背景圖旋轉(zhuǎn)效果并同時(shí)要有那種聲波擴(kuò)散的效果,一開始直接是通過js來進(jìn)行動畫配置及控制斥季,發(fā)現(xiàn)這樣做要寫一推js好煩崇猫,就想著用css3動畫和過度效果來看看能不能達(dá)到效果,結(jié)果一看出來效果還很不錯(cuò)(簡單又方便)我磁。
直接上代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>波紋動畫特效</title>
    <style type="text/css">
        html,body{
            margin: 0;
            padding: 0;
            height: 100%;
            background-color: #51c77d;
        }
        .animation{
            position: relative;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: #fff;
            top: 50%;
            left: 50%;
            border: 3px solid rgba(0,0,0,0.1);
            animation: rotate 10s linear  infinite;
            animation-play-state:paused;
            -webkit-animation-play-state:paused;
        }
        .animation:before{
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height:100%;
            border: 1px solid #fff;
            border-radius: 50%;
            /*border-image:url(https://www.w3school.com.cn/i/border.png) 30 30 10 stretch;*/
            /*background-color: transparent;*/
            /*background-image: url(https://www.w3school.com.cn/i/border.png);*/
            /*background-clip:border-box;*/
            /*background-repeat:no-repeat;*/
            opacity: 0;
            animation: ripple 2s linear 1s  infinite ;
            animation-play-state:paused;
            -webkit-animation-play-state:paused;
        }
        .animation:after{
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height:100%;
            border: 1px solid #fff;
            border-radius: 50%;
            /*border-image:url(https://www.w3school.com.cn/i/border.png) 30 30 10 stretch; !*round repeat stretch*!*/
            /*background-image: url(https://www.w3school.com.cn/i/border.png) ;*/
            /*background-clip:border-box;*/
            /*background-repeat:no-repeat;*/
            /*background-color: transparent;*/
            opacity: 0;
            animation: ripple 2s linear infinite;
            animation-play-state:paused;
            -webkit-animation-play-state:paused;
        }
        .ripple{
            animation-play-state:running;
            -webkit-animation-play-state:running;
        }
        .ripple:before{
            animation-play-state:running;
            -webkit-animation-play-state:running;
        }
        .ripple:after{
            animation-play-state:running;
            -webkit-animation-play-state:running;
        }
        @keyframes ripple {
            0% {transform: scale(1);opacity: 0.0;}

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

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

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

            100% {transform: scale(2) ;opacity: 0.0;}
        }
        @keyframes rotate {
            0% {transform:rotate(0deg);}

            25% {transform:rotate(90deg);}

            50% {transform:rotate(180deg);}

            75% {transform:rotate(270deg);}

            100% {transform:rotate(360deg);}
        }

        #play{
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            border-radius: 4px;
            color: #fff;
            border: 1px solid #fff;
            margin-top: 15px;
            cursor: pointer;
        }
        #pause{
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            border-radius: 4px;
            color: #fff;
            border: 1px solid #fff;
            margin-top: 15px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="animation ">
        <img style="display: block; width: 100%; height: 100%; border-radius: 50%;" src="http://p1.music.126.net/DSTg1dR7yKsyGq4IK3NL8A==/109951163046050093.jpg?param=300x300">
        <audio id="audio" src="http://music.163.com/song/media/outer/url?id=513360721.mp3" preload="load">您的瀏覽器不支持 audio 標(biāo)簽圃阳。</audio>
    </div>
    <div id="play">播放</div>
    <div id="pause">暫停</div>
    <script>
        document.getElementById("play").onclick = function () {
            document.querySelector(".animation").classList.add("ripple");
            document.querySelector("#audio").play();
        };
        document.getElementById("pause").onclick = function () {
            document.querySelector(".animation").classList.remove("ripple");
            document.querySelector("#audio").pause();
        }
    </script>
</body>
</html>

預(yù)覽地址: https://codepen.io/x447618716/pen/ZEERbpM
播放效果通過音頻狀態(tài)來控制

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末厌衔,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子捍岳,更是在濱河造成了極大的恐慌富寿,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件锣夹,死亡現(xiàn)場離奇詭異页徐,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)银萍,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進(jìn)店門变勇,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人贴唇,你說我怎么就攤上這事搀绣。” “怎么了戳气?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵链患,是天一觀的道長。 經(jīng)常有香客問我瓶您,道長麻捻,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任览闰,我火速辦了婚禮芯肤,結(jié)果婚禮上巷折,老公的妹妹穿的比我還像新娘压鉴。我一直安慰自己,他們只是感情好锻拘,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布油吭。 她就那樣靜靜地躺著,像睡著了一般署拟。 火紅的嫁衣襯著肌膚如雪婉宰。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天推穷,我揣著相機(jī)與錄音心包,去河邊找鬼。 笑死馒铃,一個(gè)胖子當(dāng)著我的面吹牛蟹腾,可吹牛的內(nèi)容都是我干的痕惋。 我是一名探鬼主播,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼娃殖,長吁一口氣:“原來是場噩夢啊……” “哼值戳!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起炉爆,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤堕虹,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后芬首,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體赴捞,經(jīng)...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年郁稍,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了螟炫。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,133評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡艺晴,死狀恐怖昼钻,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情封寞,我是刑警寧澤然评,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站狈究,受9級特大地震影響碗淌,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜抖锥,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一亿眠、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧磅废,春花似錦纳像、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至宫峦,卻和暖如春岔帽,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背导绷。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工犀勒, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓贾费,卻偏偏與公主長得像枚碗,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子铸本,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評論 2 355