您当前的位置: 首页 > 

暂无认证

  • 3浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

dom啦12 简易轮播图

发布时间:2020-09-06 16:19:41 ,浏览量:3

<!DOCTYPE html> <html> <head> <title></title> <style type="text/css"> *{padding: 0px;margin: 0px;} div { width: 670px; border: 1px solid red; margin: 100px auto; position: relative; } div>img { vertical-align: bottom; } p { position: absolute; width: 100%; left: 0px; top: 50%; transform: translateY(-50%); display: flex; justify-content: space-between; } p>span { display: inline-block; width: 30px; height: 60px; line-height: 60px; text-align: center; font-size: 40px; color: #FFF; background: rgba(0,0,0,0.5); } </style> </head> <body> <div> <img src="images/ad1.jpg" alt=""> <p> <span id="pre">&lt;</span> <span id="next">&gt;</span> </p> </div> <script type="text/javascript"> let qq=document.querySelector("img"); let preBtn = document.querySelector("#pre"); let nextBtn = document.querySelector("#next"); let images=["images/ad1.jpg", "images/ad2.jpg", "images/ad3.jpg", "images/ad4.jpg", "images/ad5.jpg",]; let currentIndex=0; let maxIndex=images.length-1; preBtn.onclick=function() { currentIndex--; if(currentIndex<0) { currentIndex=maxIndex; } qq.src=images[currentIndex]; } nextBtn.onclick=function() { currentIndex++; if(currentIndex>maxIndex) { currentIndex=0; } qq.src=images[currentIndex]; } </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.0871s