原生JS实现无缝轮播图片
本文实例为大家分享了JS实现无缝轮播图的具体代码,供大家参考,具体内容如下
运动插件
functionanimove(obj,distance,speed,callback){//调用的变量目标距离速度回调函数
clearInterval(obj.timer);
obj.timer=setInterval(function(){
letstep=(distance-obj.offsetLeft)/10;
step=step>0?Math.ceil(step):Math.floor(step);
if(obj.offsetLeft==distance){
clearInterval(obj.timer);
if(callback){
callback();
}
}
obj.style.left=obj.offsetLeft+step+'px';
},speed)
}
CSS代码
*{
margin:0;
padding:0;
}
ul,li{
list-style:none;
}
.box{
width:1226px;
height:460px;
margin:100pxauto;
position:relative;
overflow:hidden;
}
.pic-box{
width:4904px;
position:absolute;
}
.pic-box>li{
float:left;
}
.point{
position:absolute;
bottom:20px;
left:50%;
transform:translateX(-50%);
}
.point>li{
float:left;
width:8px;
height:8px;
border:1pxsolidblueviolet;
margin:04px;
border-radius:50%;
}
.point>.active{
background-color:orange;
}
.left-btn,
.right-btn{
width:50px;
height:40px;
background-color:rgba(0,0,0,.5);
text-align:center;
line-height:40px;
font-size:20px;
color:white;
position:absolute;
top:50%;
transform:translateY(-50%);
}
.left-btn{
left:0;
}
.right-btn{
right:0;
}
HTML代码
<