css小点,css3效果:animate实现点点点loading动画效果(二)
box-shadow實(shí)現(xiàn)的打點(diǎn)效果
簡(jiǎn)介
box-shadow理論上可以生成任意的圖形效果,當(dāng)然也就可以實(shí)現(xiàn)點(diǎn)點(diǎn)點(diǎn)的loading效果了。
實(shí)現(xiàn)原理
html代碼,首先需要寫(xiě)如下html代碼以及class類(lèi)名:
訂單提交中
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個(gè)點(diǎn) */
animation: dot 4s infinite step-start both; /* for IE10+, ... */
*zoom: expression(this.innerHTML = '...'); /* for IE7. 若無(wú)需兼容IE7, 此行刪除 */
}
.dotting:before { content: '...'; } /* for IE8. 若無(wú)需兼容IE8, 此行以及下一行刪除*/
.dotting::before { content: ''; } /* for IE9+ 覆蓋 IE8 */
:root .dotting { margin-right: 8px; } /* for IE9+,FF,CH,OP,SF 占據(jù)空間*/
@keyframes dot {
25% { box-shadow: none; } /* 0個(gè)點(diǎn) */
50% { box-shadow: 2px 0 currentColor; } /* 1個(gè)點(diǎn) */
75% { box-shadow: 2px 0 currentColor, 6px 0 currentColor; /* 2個(gè)點(diǎn) */ }
}
這里用到了currentColor這個(gè)關(guān)鍵字,IE9+瀏覽器支持,其可以讓CSS生成的圖形的顏色跟所處環(huán)境的color屬性值一樣,也就是跟文字顏色一樣。
各瀏覽器實(shí)現(xiàn)的效果如圖所示:
不足之處
雖然幾乎所有瀏覽器都有模有樣,但是,從效果上講,還是有瑕疵的,IE10+以及FireFox瀏覽器下的點(diǎn)的邊緣有些虛(參見(jiàn)下截圖),雖然CSS代碼并沒(méi)有設(shè)置盒陰影模糊。這種羽化現(xiàn)象可以讓IE以及FireFox在大數(shù)值盒陰影時(shí)候效果更接近photoshop的陰影效果;但是,在小尺寸陰影時(shí)候,并不是我們想要的。
border + background實(shí)現(xiàn)的打點(diǎn)效果
實(shí)現(xiàn)原理
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個(gè)點(diǎn) */
50% { border-right-color: transparent; background-color: transparent; } /* 1個(gè)點(diǎn) */
75% { border-right-color: transparent; } /* 2個(gè)點(diǎn) */
}
說(shuō)明:
1.同樣是4秒動(dòng)畫(huà),每秒鐘顯示1個(gè)點(diǎn);
2.IE7/IE8實(shí)現(xiàn)原理跟上面box-shadow方法一致,都是內(nèi)容生成,如果無(wú)需兼容IE7/IE8, 可以按照第一個(gè)例子CSS代碼注釋說(shuō)明刪除一些CSS;
3.currentColor關(guān)鍵字可以讓圖形字符化,必不可少;
4.最大功臣是CSS3 background-clip屬性,可以讓IE9+瀏覽器下左右padding沒(méi)有背景色,于是形成了等分打點(diǎn)效果。
5.box-sizing是讓現(xiàn)代瀏覽器和IE7/IE8占據(jù)寬度完全一樣的功臣:IE7/IE8實(shí)際寬度是width+padding-right為12像素,其他現(xiàn)代瀏覽器為width+margin-left也是12像素;
6.這里CSS代碼主要用來(lái)展示原理,故沒(méi)有顯示-webkit-animation以及@-webkit-keyframes私有前綴,實(shí)際目前還是需要的;
總結(jié)
以上是生活随笔為你收集整理的css小点,css3效果:animate实现点点点loading动画效果(二)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Redhat rpm常用命令以及如何配置
- 下一篇: 2022年新型智慧城市整体规划建设方案