CSS3實現載入中的動畫效果例子

來源:互聯網
上載者:User


Loading 的菊花圖形組合的不太好,基本上實現這個功能了
動畫解析

這個動畫用到的 CSS3 特性:

transform 主要使用 transform 屬性的 rotate,將線條組合成 Loading 圖形 (也就是常見的菊花圖形)

animation 實現將線條顏色由淺到深,再由深到淺來回變換的動畫,通過 animation-delay 屬性來使顏色的變換產生過渡的效果,從而達到類似於 Loading 動畫的效果

效果執行個體

HTML Code

<div class="loading">
    <span class="line1"></span>
    <span class="line2"></span>
    <span class="line3"></span>
    <span class="line4"></span>
    <span class="line5"></span>
    <span class="line6"></span>
    <span class="line7"></span>
    <span class="line8"></span>
</div>

CSS Code

.loading {
    width: 80px;
    height: 60px;
    margin: 0 auto;
    position: relative;
}
span {
    width: 4px;
    height: 20px;
    background-color: #ccc;
    position: absolute;
    left: 38px;
    -webkit-animation: loading 1s infinite;
}
.line1 {
    background-color: #000;
    -webkit-transform: rotate(0deg);
            transform: rotate(0deg);
    -webkit-animation-delay: .3s;
}
.line2 {
    top: 5px;
    left: 52px;
    -webkit-transform: rotate(45deg);
            transform: rotate(45deg);
    -webkit-animation-delay: .4s;
}
.line3 {
    top: 18px;
    left: 57px;
    -webkit-transform: rotate(90deg);
            transform: rotate(90deg);
    -webkit-animation-delay: .5s;
}
.line4 {
    top: 31px;
    left: 52px;
    -webkit-transform: rotate(135deg);
            transform: rotate(135deg);
    -webkit-animation-delay: .6s;
}
.line5 {
    top: 37px;
    -webkit-animation-delay: .7s;
}
.line6 {
    top: 32px;
    left: 24px;
    -webkit-transform: rotate(-135deg);
            transform: rotate(-135deg);
    -webkit-animation-delay: .8s;
}
.line7 {
    top: 18px;
    left: 19px;
    -webkit-transform: rotate(-90deg);
            transform: rotate(-90deg);
    -webkit-animation-delay: .9s;
}
.line8 {
    top: 5px;
    left: 24px;
    -webkit-transform: rotate(-45deg);
            transform: rotate(-45deg);
    -webkit-animation-delay: 1s;
}
@-webkit-keyframes loading {
    0% {
        background-color: #ccc;
    }
    50% {
        background-color: #000;
    }
    100% {
        background-color: #ccc;
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.