纯CSS给网站LOGO添加扫光效果

来源:互联网 发布:PHP中成代理链接怎么做 编辑:程序博客网 时间:2024/04/28 06:13

自从知更鸟的Begin主题实现网站Logo扫光特效之后就有很多网站也效仿起来添加Logo扫光效果了,这个效果看起来还是比较炫的。于是我就看了下知更鸟的实现方式和其他一些博友实现的方式,发现基本上都是用 :before 选择器实现的扫光效果,现在把代码和实现方式分享出来,觉得好看的可以在自己的站点上试一试。

下面用一个HTML结构演示来说明一下:

Markup
<div class="logo"><a  href="http://www.chendexin.com/" rel="home" itemprop="url"><img src="http://www.chendexin.com/images/logo.png" alt="logo" itemprop="logo" width="150" height="50"></a></div>

Logo扫光效果实现方式:

1、用 CSS3 伪元素 :bfore 或 :after 添加一扫光层;

2、用 transform:rotate(-45deg) 旋转 45 度;

3、@ keyframes 规则来控制扫光效果的起始位置和结束位置;

4、用 CSS 控制位置和动画时间等。

Logo扫光效果CSS样式:

CSS
/**logo扫光效果CSS**/#logo:before{  /**根据logo外div样式名称修改before前名称**/    content:"";    position: absolute;    left: -665px; /**第一个数字参数控制扫光速度,数字越大越慢**/    top: -460px;    width: 200px;    height: 10px; /**光标的宽度,可根据实际调整**/    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;/**第一个数字参数控制扫光速度,数字越大越慢**/}@-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; }}

需要注意的几点:

1、:before 选择器在被选元素的内容前面插入内容。

2、可以使用 content 属性来指定要插入的内容。

3、所有主流浏览器都支持 :before选择器。

4、: before在IE8中运行,必须声明 <!DOCTYPE> 。

顶: 0踩: 0

来源:陈德馨博客,转载请以链接形式标明本文地址!

本文地址:http://www.chendexin.com/archives/541.html

1 0
原创粉丝点击