效果:
http://115.159.53.185/test/lunbo/
有bug
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<style type="text/css">
#imageBox{
width: 720px;
height: 300px;
margin: 50px auto;
list-style: none;
position: relative;
overflow: hidden;
}
#imageBox li{
width: 100%;
height: 100%;
position: absolute;
left: 100%;
transition: all 0.3s;//过渡
z-index: 5;
}
#imageBox li:first-child{
left: -100%;
}
#imageBox li:nth-child(2){
left:0;
}
#imageBox li img{
width: 100%;
height: 100%;
}
#next{
margin-left: 750px;
}
</style>
<body>
<ul id="imageBox">
<li><img src="img/1.png"/></li>
<li><img src="img/2.png"/></li>
<li><img src="img/3.png"/></li>
<li><img src="img/4.png"/></li>
</ul>
<button id="next">next</button>
<button id="prev">prev</button>
<script type="text/javascript">
var lis = document.getElementById("imageBox").getElementsByTagName('li');
var next = document.getElementById("next");
var prev = document.getElementById("prev");
var nowIndex = 1;
var count = lis.length;
next.onclick = function(){
for(var i = 0; i < count; i++){
if(i!=nowIndex){
lis[i].style.left = '100%';
}
}
//下一个图片的编号
var nextIndex = nowIndex + 1 >= count ? 0 : nowIndex + 1;
//当前图片向左:
lis[nowIndex].style.left = '-100%';
lis[nowIndex].style.zIndex = '5';
//下一页从右向左
lis[nextIndex].style.left = '0%';
lis[nextIndex].style.zIndex = '6';
nowIndex = nextIndex;
}
prev.onclick = function(){
for(var i = 0; i < count; i++){
if(i!=nowIndex){
lis[i].style.left = '-100%';
}
}
//下一个图片的编号
var nextIndex = nowIndex != 0 ? nowIndex-1 : count-1;
//当前图片向左:
lis[nowIndex].style.left = '100%';
lis[nowIndex].style.zIndex = '5';
//下一页从右向左
lis[nextIndex].style.left = '0%';
lis[nextIndex].style.zIndex = '6';
nowIndex = nextIndex;
}
</script>
</body>
</html>