css大風(fēng)車(四葉草)

效果圖走一波

有些卡頓,gif沒錄制好

布局
結(jié)構(gòu)非常簡單,四塊葉子

    <body>
        <div class="cloverBox">
            <div class="clover c1"></div>
            <div class="clover c2"></div>
            <div class="clover c3"></div>
            <div class="clover c4"></div>
        </div>
    </body>

class='cloverBox'為葉子容器
clover為葉子共有屬性
c1,c2,c3,c4為葉子私有屬性

<style>
        *{margin: 0;padding: 0;}
        html,body{display: flex;width: 100%;height: 100%;background: #f7f7f7;align-items: center;}
        .cloverBox{
            position: absolute;
            top: 50%;
            margin-top: -200px;
            left: 50%;
            margin-left: -200px;
            width: 400px;
            height: 400px;
            transform: rotate(0deg);
        }
        .clover{
            width: 50%;
            height: 50%;
            float: left;
            transition: all .6s;
            cursor: pointer;
        }
        .c1{background: #A82125;border-radius: 0 50% 0 50%;}
        .c2{background: #DFD03E;border-radius: 50% 0 50% 0;}
        .c3{background: #88DD3E;border-radius: 50% 0 50% 0;}
        .c4{background: #1EA8D7;border-radius: 0 50% 0 50%;}
    </style>

border-radius屬性用于創(chuàng)建圓角,對應(yīng)的值為border-radius: 左上角 右上角 右下角 左下角;

一個靜態(tài)的布局就完成了


{ISBJCHZ@_CCGQG5R0@W_7T.png

如何讓他動起來的,并且鼠標(biāo)懸浮轉(zhuǎn)動停止,被選中的葉子縮小呢

給葉子容器cloverBox類添加動畫屬性animation

       .cloverBox{
            position: absolute;
            top: 50%;
            margin-top: -200px;
            left: 50%;
            margin-left: -200px;
            width: 400px;
            height: 400px;
            transform: rotate(0deg);
            /* 動畫屬性 */
            animation: round 10s linear infinite forwards;
        }

animation: round 10s linear infinite forwards;

round綁定到選擇器的 keyframe 名稱
10s執(zhí)行動畫所需要的時間
linear動畫從頭到尾的速度是相同的(默認(rèn)的話動畫以低速開始,然后加快,在結(jié)束前變慢)
infinite規(guī)定動畫應(yīng)該無限次播放
forwards將動畫屬性應(yīng)用在元素上

屬性設(shè)置完畢,接下來實(shí)現(xiàn)執(zhí)行的動畫效果@keyframes
主要是實(shí)現(xiàn)元素的旋轉(zhuǎn)角度從0~360transform: rotate(0deg)

       @keyframes round{
            from{
                transform: rotate(0deg);
            }
            to
            {
                transform: rotate(360deg);
            }
        }

在這里我沒有設(shè)置各瀏覽器的兼容,如需要!自行添加

已經(jīng)可以旋轉(zhuǎn),接下如何實(shí)現(xiàn)鼠標(biāo)懸浮轉(zhuǎn)動停止呢

主要用到了animation-play-state: paused|running;
animation-play-state 屬性規(guī)定動畫正在運(yùn)行還是暫停paused 規(guī)定動畫已暫停,running規(guī)定動畫正在播放

所以我們在鼠標(biāo)hover葉子容器cloverBox的時候暫停動畫

       .cloverBox:hover{
            animation-play-state:paused 
        }

鼠標(biāo)hover葉子clover的時候被選中的葉子縮小transform:scale(x,y) 定義 2D 縮放轉(zhuǎn)換。

        .clover:hover{
            transform: scale(0.9);
        }

所需要實(shí)現(xiàn)的效果已經(jīng)完成,完整代碼如下

<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="author" content="Cc">
        <title>四葉草</title>
    </head>
    <style>
        *{margin: 0;padding: 0;}
        html,body{display: flex;width: 100%;height: 100%;background: #f7f7f7;align-items: center;}
        .cloverBox{
            position: absolute;
            top: 50%;
            margin-top: -200px;
            left: 50%;
            margin-left: -200px;
            width: 400px;
            height: 400px;
            transform: rotate(0deg);
            /* 動畫屬性 */
            animation: round 10s linear infinite forwards;
        }
        .cloverBox:hover{
            animation-play-state:paused 
        }
        @keyframes round{
            from{
                transform: rotate(0deg);
            }
            to
            {
                transform: rotate(360deg);
            }
        }
        .clover{
            width: 50%;
            height: 50%;
            float: left;
            transition: all .6s;
            cursor: pointer;
        }
        .clover:hover{
            transform: scale(0.9);
        }
        .c1{background: #A82125;border-radius: 0 50% 0 50%;}
        .c2{background: #DFD03E;border-radius: 50% 0 50% 0;}
        .c3{background: #88DD3E;border-radius: 50% 0 50% 0;}
        .c4{background: #1EA8D7;border-radius: 0 50% 0 50%;}
    </style>
    <body>
        <div class="cloverBox">
            <div class="clover c1"></div>
            <div class="clover c2"></div>
            <div class="clover c3"></div>
            <div class="clover c4"></div>
        </div>
    </body>
</html>
點(diǎn)贊.jpg
?著作權(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)容

  • 打卡日期:2018年03月30打卡累計天數(shù):26/30 #宣言(我和媽媽一起努力踐行。相信自己行比自己行更重要〉 ...
    牛牛簡書閱讀 189評論 0 0
  • 小時候?qū)W習(xí)《賣火柴的小女孩》這篇文章時只是覺得小女孩太可憐了,沒有人愛她,在萬家燈火的圣誕夜她卻獨(dú)自一個人在街頭賣...
    Aliyachit閱讀 3,702評論 0 2
  • *本篇無對女性懷有不敬的思想,只是借述論述。 日常生活中,只要講到“小說”這個詞,大多數(shù)的人所能聯(lián)想到的是一些...
    渡芥閱讀 988評論 1 3

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