html三张图片自动轮回播放,JS -- 记一种用原生JS 完成轮播图的要领(非无穷轮回不自动切换)...

完成一个非无穷轮回不自动切换的轮播图

只需要几张图片和两个按钮(简化)

HTML部份

两个按钮,几张图片(假如有四张图)

右边按钮

左边按钮

CSS部份

动态增加删除li的class属性(native)

span{ cursor: pointer; }

#s1,#s2{

position: absolute;

top: 130px;

}

#s1{ right: 0;}

#s2{ left:0; }

ul{

width: 460px;

height: 280px;

margin: auto;

overflow: hidden;

}

li{

float: left;

display: none;

background-color: orange;

}

.active{

background-color: #dddddd;

display: block;

}

JS部份

window.οnlοad=function(){

var index = 0,

imgs = document.getElementsByTagName("li");

s1.onclick = function(e){

index++;

if(index >= imgs.length){

imgs[imgs.length-1].setAttribute("class", "active");

alert("已经是末了一张图")

return index = imgs.length-1;;

}else{

imgs[index-1].removeAttribute("class");

imgs[index].setAttribute("class", "active");

return index;

}

}

s2.οnclick=function(){

if(index>0){

imgs[index].removeAttribute("class");

imgs[index-1].setAttribute("class", "active");

index--;

return index-1;

}else{

imgs[0].setAttribute("class", "active");

alert("这是第一张图")

return index = 0;

}

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值