一个网站建设爱好者,技术交流,相互学习
当前位置:首页>>程序猿
css3 条纹背景滚动效果
发布时间:2021-11-16 10:36:08 栏目:程序猿 阅读量:1616 作者:webcms

之前在一个网站上看到这样一个效果,我一开始以为一个背景gif图片,为了验证我的想法,我打开firebug 一查看,原来不是gif。是用css3完成的。于是我就在查看css3的api帮助下尝试着 写一写,代码如下

html代码很简单 就一个div就ok,只不过在样式里面 加了一个 :after。

下面直接上css代码:

.test{margin: 100px auto; width: 250px;height: 60px; background-color: #666;position: relative;}
.test:after{ position: absolute;top: 0;left: 0;width: 100%;height: 100%;content: "";
background: -webkit-gradient(linear,0 100%,100% 0,color-stop(.25,rgba(255,255,255,.15)),color-stop(.25,transparent),color-stop(.5,transparent),color-stop(.5,rgba(255,255,255,.15)),color-stop(.75,rgba(255,255,255,.15)),color-stop(.75,transparent),to(transparent));
background: -webkit-gradient(linear,0 100%,100% 0,color-stop(.25,rgba(255,255,255,.15)),color-stop(.25,transparent),color-stop(.5,transparent),color-stop(.5,rgba(255,255,255,.15)),color-stop(.75,rgba(255,255,255,.15)),color-stop(.75,transparent),to(transparent));
background: -webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);
background: -moz-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);
background: -o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);
background: linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);
-webkit-animation: twb-bar 2s linear infinite;
-moz-animation: twb-bar 2s linear infinite;
-ms-animation: twb-bar 2s linear infinite;
-o-animation: twb-bar 2s linear infinite;
animation: twb-bar 2s linear infinite;
-webkit-background-size: 40px 40px;
-moz-background-size: 40px 40px;
-o-background-size: 40px 40px;
background-size: 40px 40px;
}
@-webkit-keyframes twb-bar {
from {background-position: 40px 0;}
to { background-position: 0 0; }
}
@-moz-keyframes twb-bar {
from { background-position: 40px 0;}
to {background-position: 0 0;}
}
@-ms-keyframes twb-bar {
from {background-position: 40px 0;}
to { background-position: 0 0;}
}
@-o-keyframes twb-bar {
from {background-position: 0 0;}
to { background-position: 40px 0;}
}
@keyframes twb-bar {
from { background-position: 40px 0;}
to { background-position: 0 0;}
}

评论:

IT视频教程
Copyright © web小工匠 保留所有权利. 渝ICP备15008469号 网站地图