1 !DOCTYPE html 2 html lang= en 3 head 4 meta charset= utf-8 5 style 6 .shadow { 7 text-align: center; 8 /* 背景顏色線性漸變 */ 9 /* 老式寫法 */10 /* linear為線性漸變,也可以用下面的那種寫法。left top,right top指的是漸變方向,左上到右上 */11 /* color-stop函數(shù),第一個(gè)表示漸變的位置,0為起點(diǎn),0.5為中點(diǎn),1為結(jié)束點(diǎn);第二個(gè)表示該點(diǎn)的顏色。所以本次漸變?yōu)閮蛇吇疑?,中間漸白色 */12 background: -webkit-gradient(linear, left top, right top, color-stop(0, #4d4d4d), color-stop(.4, #4d4d4d), color-stop(.5, white), color-stop(.6, #4d4d4d), color-stop(1, #4d4d4d));13 /* 新式寫法 */14 /* background: -webkit-linear-gradient(left top, right top, color-stop(0, #4d4d4d), color-stop(.4, #4d4d4d), color-stop(.5, white), color-stop(.6, #4d4d4d), color-stop(1, #4d4d4d)); */15 16 /* 設(shè)置為text,意思是把文本內(nèi)容之外的背景給裁剪掉 */17 -webkit-background-clip: text;18 /* 設(shè)置對(duì)象中的文字填充顏色 這里設(shè)置為透明 */19 -webkit-text-fill-color: transparent;20 /* 每隔2秒調(diào)用下面的CSS3動(dòng)畫 infinite屬性為循環(huán)執(zhí)行animate */21 -webkit-animation: animate 1.5s infinite;22 }23 /* 兼容寫法,要放在@keyframes前面 */24 @-webkit-keyframes animate {25 /* 背景從-100px的水平位置,移動(dòng)到+100px的水平位置。如果要移動(dòng)Y軸的,設(shè)置第二個(gè)數(shù)值 */26 from {background-position: -100px;}27 to {background-position: 100px;}28 }29 @keyframes animate {30 from {background-position: -100px;}31 to {background-position: 100px;}32 }33 /style 34 /head 35 body 36 div >一、直接上代碼!下面這是效果圖:
二、這個(gè)白色漸變閃過效果用CSS3做很容易也很方便,唯一不好的地方應(yīng)該就是兼容問題了。所以現(xiàn)在一般都用在移動(dòng)端上面了。
三、來啦來啦!(敲黑板) 我覺得代碼注釋已經(jīng)比較清楚了,所以畫畫重點(diǎn)就好了?。?!
1、infinite 這是循環(huán)執(zhí)行的屬性,有了它,才能一閃一閃滴!
2、-webkit-text-fill-color: transparent; 文字填充顏色為透明,沒有設(shè)置的話,看不出白色漸變劃過效果的!
3、-webkit-background-clip: text; 把文本內(nèi)容之外的背景給裁剪掉,如果不加,文字顯示不出來,只顯示漸變的顏色!
4、color-stop() 漸變的color-stop 函數(shù),表示漸變的位置和顏色,就是它,我們才能想在哪里漸變就哪里漸變,再讓它移動(dòng)起來,就出現(xiàn)一閃一閃的效果了!
四、最后,說一下思路:
首先,設(shè)置一個(gè)中間白色、兩邊灰色的漸變背景色;
其次,文字填充顏色設(shè)為透明(才能看到白色背景);
接著,把文字之外的背景色給裁剪掉(只顯示文字);
最后,用@keyframes,讓背景白色位置循環(huán)從左到右執(zhí)行。
如果還有任何問題,歡迎留言哈?。?!
以上就是分享一個(gè)css特效--向右循環(huán)閃過的詳細(xì)內(nèi)容,html教程
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。
新聞熱點(diǎn)
疑難解答