css有个执行简单动画的写法,比如animation。
我给你个例子:
#head-pic,#head-pic2{
width:145pxheight:145pxposition:absolute
top:200px
left:68px
z-index:2
border-radius:100px
-webkit-border-radius:100px
-moz-border-radius:100px
border:3px solid #fff
}
/*为浏览器兼容设置*/
@keyframes headpic-slider{
from{background:url(../images/head-pic.jpg)opacity:1.0}
to{background:url(../images/head-pic.jpg)opacity:0}
}
@keyframes headpic-slider2{
from{background:url(../images/head-pic2.jpg)opacity:0}
to{background:url(../images/head-pic2.jpg)opacity:1.0}
}
@-moz-keyframes headpic-slider{
from{background:url(../images/head-pic.jpg)opacity:1.0}
to{background:url(../images/head-pic.jpg)opacity:0}
}
@-moz-keyframes headpic-slider2{
from{background:url(../images/head-pic2.jpg)opacity:0}
to{background:url(../images/head-pic.jpg)opacity:1.0}
}
@-webkit-keyframes headpic-slider{
from{background:url(../images/head-pic.jpg)opacity:1.0}
to{background:url(../images/head-pic.jpg)opacity:0}
}
@-webkit-keyframes headpic-slider2{
from{background:url(../images/head-pic2.jpg)opacity:0}
to{background:url(../images/head-pic2.jpg)opacity:1.0}
}
@-o-keyframes headpic-slider{
from{background:url(../images/head-pic.jpg)opacity:1.0}
to{background:url(../images/head-pic.jpg)opacity:0}
}
@-o-keyframes headpic-slider2{
from{background:url(../images/head-pic2.jpg)opacity:0}
to{background:url(../images/head-pic2.jpg)opacity:1.0}
}
#head-pic{
animation:headpic-slider 20s linear infinite
-moz-animation:headpic-slider 20s linear infinite
-webkit-animation:headpic-slider 20s linear infinite
}
#head-pic2{
animation:headpic-slider2 20s linear infinite
-moz-animation:headpic-slider2 20s linear infinite
-webkit-animation:headpic-slider2 20s linear infinite
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=utf-8" />
<title>纯css实现图片相册幻灯片切换</title>
<style type="text/css">
*{ margin:0 padding:0 list-style:none}
.lanrenzhijia{ width:180px height:162px margin:100px auto}
.lanrenzhijia dl { position:relative width:160px height:142px border:10px solid #EFEFDA }
.lanrenzhijia dd { width:160px height:120pxoverflow:hidden}
.lanrenzhijia img { border:2px solid #000 }
.lanrenzhijia dt { position:absolute right:0px bottom:0pxwidth:160pxheight:22px background:#FBFBEA }
.lanrenzhijia a {display:blockfloat:rightmargin:2pxwidth:18px height:18pxtext-align:center color:#fff text-decoration:none background:#666filter:alpha(opacity=70) opacity:.7}
.lanrenzhijia a:hover {background:#000}
</style>
</head>
<body>
<div class="lanrenzhijia">
<dl>
<dt>
<a href="#indexa6">6</a><a href="#indexa5">5</a><a href="#indexa4">4</a><a href="#indexa3">3</a><a href="#indexa2">2</a><a href="#indexa1">1</a>
</dt>
<dd>
<img id="indexa1" name="indexa1" src="images/图片1.jpg" />
<img id="indexa2" name="indexa2" src="images/图片2.jpg" />
<img id="indexa3" name="indexa3" src="images/图片3.jpg" />
<img id="indexa4" name="indexa4" src="images/图片4.jpg" />
<img id="indexa5" name="indexa5" src="images/图片5.jpg" />
<img id="indexa6" name="indexa6" src="images/图片6.jpg" />
</dd>
</dl>
</div>
</body>
</html>
参考资料:懒人之家