css小点,css3效果:animate实现点点点loading动画效果(二)
box-shadow實現的打點效果
簡介
box-shadow理論上可以生成任意的圖形效果,當然也就可以實現點點點的loading效果了。
實現原理
html代碼,首先需要寫如下html代碼以及class類名:
訂單提交中
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屬性值一樣,也就是跟文字顏色一樣。
各瀏覽器實現的效果如圖所示:
不足之處
雖然幾乎所有瀏覽器都有模有樣,但是,從效果上講,還是有瑕疵的,IE10+以及FireFox瀏覽器下的點的邊緣有些虛(參見下截圖),雖然CSS代碼并沒有設置盒陰影模糊。這種羽化現象可以讓IE以及FireFox在大數值盒陰影時候效果更接近photoshop的陰影效果;但是,在小尺寸陰影時候,并不是我們想要的。
border + background實現的打點效果
實現原理
html代碼
訂單提交中
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個點 */
}
說明:
1.同樣是4秒動畫,每秒鐘顯示1個點;
2.IE7/IE8實現原理跟上面box-shadow方法一致,都是內容生成,如果無需兼容IE7/IE8, 可以按照第一個例子CSS代碼注釋說明刪除一些CSS;
3.currentColor關鍵字可以讓圖形字符化,必不可少;
4.最大功臣是CSS3 background-clip屬性,可以讓IE9+瀏覽器下左右padding沒有背景色,于是形成了等分打點效果。
5.box-sizing是讓現代瀏覽器和IE7/IE8占據寬度完全一樣的功臣:IE7/IE8實際寬度是width+padding-right為12像素,其他現代瀏覽器為width+margin-left也是12像素;
6.這里CSS代碼主要用來展示原理,故沒有顯示-webkit-animation以及@-webkit-keyframes私有前綴,實際目前還是需要的;
總結
以上是生活随笔為你收集整理的css小点,css3效果:animate实现点点点loading动画效果(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Redhat rpm常用命令以及如何配置
- 下一篇: 2022年新型智慧城市整体规划建设方案
