效果可能不是太好
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type= "text/css">
#top_img{
width: 500px;
height:400px;
margin: 0 auto;
border:1px solid black;
background-size:500px 400px;
transition:background-image 0.8s ease-in-out;
position: relative;
top:0;
left: 0;
}
ul{
position:absolute;
bottom:0;
}
li{
float: left;
width: 10px;
height: 10px;
margin-left:10px;
list-style-type: none;
}
.d{
width:10px;
height: 10px;
border-radius:5px;
background:#fff;
}
</style>
</head>
<body>
<div id = "top_img">
<ul >
<li class = "li"><div class = "d"></div> </li>
<li class = "li"> <div class = "d"></div></li>
<li class = "li"> <div class = "d"></div></li>
<li class = "li"> <div class = "d"></div></li>
</ul>
</div>
<script type="text/javascript" >
var imgPath = new Array("0039.jpg", "0040.jpg", "0041.jpg", "0042.jpg");
var top_img = $("top_img");
var len = imgPath.length;
var now = len-1, last = 0;
function getLast(now){
return ((now-1)%len+len)%len;
}
function $(id){
return document.getElementById(id);
}
function changeImage(){
now++;
if(now >= len)now = 0;
top_img.style.backgroundImage = "url("+imgPath[now]+")";
last = getLast(now);
document.getElementsByClassName("d")[last].style.backgroundColor = "#fff";
document.getElementsByClassName("d")[now].style.background = "red";
}
var interval1 = window.setInterval("changeImage()", 2000);
</script>
</body>
</html>