console
window.onload=function(){
var oPrev=document.getElementById('prev'),
oContainer=document.getElementById('parent'),
oNext=document.getElementById('next'),
oList=document.getElementById('oul'),
oBtn=document.getElementById('ous').getElementsByTagName('li'),
index= 1,
timer=null,
timers=null,
interval=3000;
nowTime=+new Date();
oNext.onclick=function(){
animate(-1000);
}
oPrev.onclick=function(){
animate(1000);
}
function showBtn(index){
for (var i = 0; i < oBtn.length ; i++) {
if( oBtn[i].className == 'ls'){
oBtn[i].className = '';
break;
}
}
oBtn[index-1].className = 'ls';
}
function animate(offset){
if(+new Date()- nowTime>800){
var speed=0,
oLeft=parseInt(oList.style.left)+offset;
if(offset<0){
if(index==5){
index=0;
}
index++;
}else if(offset>0){
index--
if(index==0){
index=5
}
}
var runs=function(){
speed=(oLeft-parseInt(oList.style.left))/10;
speed=(speed>0)?Math.ceil(speed):Math.floor(speed);
if(parseInt(oList.style.left)>oLeft||parseInt(oList.style.left)<oLeft){
oList.style.left=parseInt(oList.style.left)+speed+'px';
timer=setTimeout(runs,8)
}else{
if(oLeft<-5000){
oList.style.left=offset+'px';
}
if(oLeft>-1000){
oList.style.left=-5*offset+'px';
}
}
}
runs();
nowTime=new Date();
showBtn(index);
}
}
for (var i = 0; i < oBtn.length; i++) {
oBtn[i].index=i;
oBtn[i].onclick = function () {
if(this.className == 'on') {
return;
}
var myIndex = this.index+1;
var offset = -1000 * (myIndex - index);
animate(offset);
index = myIndex;
showBtn(index);
}
}
oContainer.onmouseover = stop;
oContainer.onmouseout = play;
play();
function play() {
clearInterval(timers);
timers = setInterval(function () {
oNext.onclick();
play();
}, interval);
}
function stop() {
clearInterval(timers);
}
}
<div class='parent' id="parent">
<ul class='oul' id='oul' style="left:-1000px">
<li><img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img5.jpg"></li>
<li><img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img1.jpg"></li>
<li><img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img2.jpg"></li>
<li><img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img3.jpg"></li>
<li><img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img4.jpg"></li>
<li><img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img5.jpg"></li>
<li><img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img1.jpg"></li>
</ul>
<a id="prev" href="javascript:void(0)"></a>
<a id="next" href="javascript:void(0)"></a>
<ul class="us" id='ous'>
<li class="ls"><a href="javascript:void(0)">1</a></li>
<li><a href="javascript:void(0)">2</a></li>
<li><a href="javascript:void(0)">3</a></li>
<li><a href="javascript:void(0)">4</a></li>
<li><a href="javascript:void(0)">5</a></li>
</ul>
</div>
*/
* {
padding: 0;
margin: 0;
list-style-type: none;
}
body {
background: black;
color: white;
}
.parent {
width: 1000px;
height: 625px;
/*border: 1px solid red;*/
margin: 100px auto;
position: relative;
overflow: hidden;
}
.oul {
height: 625px;
width: 7000px;
position: absolute;
top: 0;
}
.oul li {
float: left;
height: 100%;
width: 1000px;
}
.oul li img {
height: 100%;
width: 100%;
}
width: 50px;
height: 625px;
display: block;
position: absolute;
left: 0;
top: 0;
background:
transition: all 1s;
}
background-color:
}
background-color:
}
width: 50px;
height: 625px;
display: block;
position: absolute;
right: 0;
top: 0;
background:
transition: all 1s;
}
ul.us {
width: 200px;
height: 20px;
overflow: hidden;
position: absolute;
right: 60px;
bottom: 10px;
}
ul.us li {
width: 40px;
text-align: center;
height: 20px;
display: block;
float: left;
border-radius: 50%;
background:
opacity: 0.6;
transition: all 1s;
}
ul.us li a{
text-decoration:none;
color:white;
}
ul.us li.ls {
background:
}