bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

純CSS如何實現一個沙漏的動畫效果

今天就跟大家聊聊有關純CSS如何實現一個沙漏的動畫效果,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

創新互聯公司是一家專業提供泗洪企業網站建設,專注與做網站、成都做網站、H5網站設計、小程序制作等業務。10年已為泗洪眾多企業、政府機構等服務。創新互聯專業網站制作公司優惠進行中。

效果預覽

純CSS如何實現一個沙漏的動畫效果

源代碼下載

https://github.com/comehope/front-end-daily-challenges

代碼解讀

定義 dom,容器中包含 2 個元素,分別代表沙漏的上半部和下半部:

<div class="loader">
    <span class="top"></span>
    <span class="bottom"></span>
</div>

居中顯示:

body {
    margin: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: gainsboro;
}

定義容器尺寸,并設置子元素整體布局:

.loader {
    width: 4.3em;
    height: 9.8em;
    font-size: 10px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
}

畫出 2 個正方形:

.top,
.bottom {
    width: 3.5em;
    height: 3.5em;
    border-style: solid;
    border-color: saddlebrown;
}

通過邊框、圓角和旋轉,把 2 個正方形變成沙漏形狀:

.top,
.bottom {
    border-width: 0.2em 0.2em 0.6em 0.6em;
    border-radius: 50% 100% 50% 30%;
}

.top {
    transform: rotate(-45deg);
}

.bottom {
    transform: rotate(135deg);
}

用偽元素畫出沙子,上部的沙子的頂部是大圓弧,下部的沙子的頂部是小圓弧:

.top::before,
.bottom::before {
    content: '';
    position: absolute;
    width: inherit;
    height: inherit;
    background-color: deepskyblue;
}

.top::before {
    border-radius: 0 100% 0 0;
}

.bottom::before {
    border-radius: 0 0 0 35%;
}

定義沙子的動畫屬性:

.top::before,
.bottom::before {
    animation: 2s linear infinite;
}

增加沙子從沙漏的上半部落下的動畫效果:

.top::before {
    animation-name: drop-sand;
}

@keyframes drop-sand {
    to {
        transform: translate(-2.5em, 2.5em);
    }
}

增加沙子的沙漏在下半部堆積的動畫效果:

.bottom::before {
    transform: translate(2.5em, -2.5em);
    animation-name: fill-sand;
}

@keyframes fill-sand {
    to {
        transform: translate(0, 0);
    }
}

隱藏沙漏上半部和下半部容器外的部分,此時上面 2 個動畫的疊加效果是沙子從上半部漏下,慢慢在下半部堆積:

.top,
.bottom {
    overflow: hidden;
}

用外層容器的偽元素制作一個窄長條,模擬流動的沙子:

.loader::after {
    content: '';
    position: absolute;
    width: 0.2em;
    height: 4.8em;
    background-color: deepskyblue;
    top: 1em;
}

增加沙子流動的動畫效果:

.loader::after {
    animation: flow 2s linear infinite;
}

@keyframes flow {
    10%, 100% {
        transform: translateY(3.2em);
    }
}

最后,增加沙漏的翻轉動畫:

.loader {
    animation: rotating 2s linear infinite;
}

@keyframes rotating {
    0%, 90% {
        transform: rotate(0);
    }
    
    100% {
        transform: rotate(0.5turn);
    }
}

大功告成!

看完上述內容,你們對純CSS如何實現一個沙漏的動畫效果有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注創新互聯行業資訊頻道,感謝大家的支持。

當前名稱:純CSS如何實現一個沙漏的動畫效果
本文地址:http://vcdvsql.cn/article0/pddhoo.html

成都網站建設公司_創新互聯,為您提供移動網站建設、網站設計公司、ChatGPT、定制網站、網站設計微信小程序

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

綿陽服務器托管