[摘要]
在知更鳥大神的網(wǎng)站看到他的Begin主題Logo有掃光特效,看起來還是比較炫的。研究了一下,發(fā)現(xiàn)是用:before選擇器實現(xiàn)的掃光效果,現(xiàn)在把代碼甩出來,覺得好看的可以在自己的站點上試一試。
在知更鳥大神的網(wǎng)站看到他的Begin主題Logo有掃光特效,看起來還是比較炫的。研究了一下,發(fā)現(xiàn)是用:before選擇器實現(xiàn)的掃光效果,現(xiàn)在把代碼甩出來,覺得好看的可以在自己的站點上試一試。
Logo掃光方法
方法很簡單,只需要添加一段css代碼即可,如果你是WordPress程序,那么請在當前主題css文件最下方添加如下代碼,需注意:代碼中的#logo:before,根據(jù)自己的實際情況修改為當前主題的Logo元素選擇器名稱。
/**logo掃光效果CSS**/ .logo:before{ /**根據(jù)logo外div樣式名稱修改before前名稱**/ content:""; position: absolute; left: -665px; /**第一個數(shù)字參數(shù)控制掃光速度,數(shù)字越大越慢**/ top: -460px; width: 200px; height: 10px; /**光標的寬度,可根據(jù)實際調(diào)整**/ background-color: rgba(255,255,255,.5); -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -ms-transform: rotate(-45deg); -o-transform: rotate(-45deg); transform: rotate(-45deg); -webkit-animation: searchLights 1s ease-in 1s infinite; -o-animation: searchLights 1s ease-in 1s infinite; animation: searchLights 1.5s ease-in 1s infinite;/**第一個數(shù)字參數(shù)控制掃光速度,數(shù)字越大越慢**/ } @-webkit-keyframes searchLights { 0% { left: -100px; top: 0; } to { left: 120px; top: 100px; } } @-o-keyframes searchLights { 0% { left: -100px; top: 0; } to { left: 120px; top: 100px; } } @-moz-keyframes searchLights { 0% { left: -100px; top: 0; } to { left: 120px; top: 100px; } } @keyframes searchLights { 0% { left: -100px; top: 0; } to { left: 120px; top: 100px; } }
當然,此效果也適用于其他建站程序,其僅僅是一個CSS效果而已。
:before 選擇器介紹
:before 選擇器在被選元素的內(nèi)容前面插入內(nèi)容。
請使用 content 屬性來指定要插入的內(nèi)容。
所有主流瀏覽器都支持:before選擇器。
注意: before在IE8中運行,必須聲明 <!DOCTYPE> 。
轉(zhuǎn)載請注明出處 AE博客|墨淵 ? 使用:before選擇器給你的Logo添加掃光特效
發(fā)表評論