利用css3的animate實現點點點loading動畫效果(二),css3animate

來源:互聯網
上載者:User

利用css3的animate實現點點點loading動畫效果(二),css3animate
box-shadow實現的打點效果簡介

box-shadow理論上可以產生任意的圖形效果,當然也就可以實現點點點的loading效果了。

實現原理

html代碼,首先需要寫如下html代碼以及class類名:

 訂單提交中<span class="dotting"></span>

css代碼

.dotting {    display: inline-block; min-width: 2px; min-height: 2px;    box-shadow: 2px 0 currentColor, 6px 0 currentColor, 10px 0 currentColor; /* for IE9+, ..., 3個點 */    animation: dot 4s infinite step-start both; /* for IE10+, ... */    *zoom: expression(this.innerHTML = '...'); /*  for IE7. 若無需相容IE7, 此行刪除 */}.dotting:before { content: '...'; } /* for IE8. 若無需相容IE8, 此行以及下一行刪除*/.dotting::before { content: ''; } /* for IE9+ 覆蓋 IE8 */:root .dotting { margin-right: 8px; } /* for IE9+,FF,CH,OP,SF 佔據空間*/@keyframes dot {    25% { box-shadow: none; }                                  /* 0個點 */    50% { box-shadow: 2px 0 currentColor; }                    /* 1個點 */    75% { box-shadow: 2px 0 currentColor, 6px 0 currentColor;  /* 2個點 */ }}

這裡用到了currentColor這個關鍵字,IE9+瀏覽器支援,其可以讓CSS產生的圖形的顏色跟所處環境的color屬性值一樣,也就是跟文字顏色一樣。

各瀏覽器實現的效果:

支援CSS3 animation動畫的瀏覽器顯示的就是打點動畫效果;對於不支援的瀏覽器,IE7/IE8顯示的是真實的字元..., IE9瀏覽器雖然也是CSS3產生,但是是靜態,沒有動畫效果;此乃漸進相容。

不足之處

雖然幾乎所有瀏覽器都有模有樣,但是,從效果上講,還是有瑕疵的,IE10+以及FireFox瀏覽器下的點的邊緣有些虛(參見下),雖然CSS代碼並沒有設定盒陰影模糊。這種羽化現象可以讓IE以及FireFox在大數值盒陰影時候效果更接近photoshop的陰影製作效果;但是,在小尺寸陰影時候,並不是我們想要的。

border + background實現的打點效果實現原理

html代碼

訂單提交中<span class="dotting"></span>

css代碼

.dotting {    display: inline-block; width: 10px; min-height: 2px;    padding-right: 2px;    border-left: 2px solid currentColor; border-right: 2px solid currentColor;       background-color: currentColor; background-clip: content-box;    box-sizing: border-box;    animation: dot 4s infinite step-start both;    *zoom: expression(this.innerHTML = '...'); /* IE7 */}.dotting:before { content: '...'; } /* IE8 */.dotting::before { content: ''; }:root .dotting { margin-left: 2px; padding-left: 2px; } /* IE9+ */@keyframes dot {    25% { border-color: transparent; background-color: transparent; }          /* 0個點 */    50% { border-right-color: transparent; background-color: transparent; }    /* 1個點 */    75% { border-right-color: transparent; }                                   /* 2個點 */}

說明:

參考地址:再說CSS3 animation實現點點點loading動畫

https://github.com/tawian/text-spinners

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.