首页 > Web开发 > 详细

JS图片轮播

时间:2020-02-21 15:16:31      阅读:49      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html >

<head>
    <meta charset="UTF-8">

    <title>Document</title>
    
</head>

<body>
    <img src="img/1.jpeg" id="flower">
    <br>
    <button id="prve">上</button>
    <button id="next">下</button>
    <script>
        // 获取id
          var flower=document.getElementById(‘flower‘);
          var nextbtn=document.getElementById(‘next‘);
          var prve=document.getElementById(‘prve‘);
          var minindex=1; maxindex=4;currentindex=minindex;
       
        //定义点击事件
      nextbtn.onclick=function(){
          currentindex++;
          if(currentindex==maxindex)
          {
              currentindex=1;
          }
          flower.setAttribute(‘src‘,‘img/‘+currentindex+‘.jpeg‘)
      }

      prve.onclick=function(){
          currentindex--;
          if(currentindex==minindex)
          {
              currentindex=4;
          }
          flower.setAttribute(‘src‘,‘img/‘+currentindex+‘.jpeg‘)
      }
    </script>
</body>

</html>

JS图片轮播

原文:https://www.cnblogs.com/lxabner/p/12340702.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!