轮播

<style>

  *{
      margin:0;
      padding:0;
  }
  li{
      list-style:none;
  }
  a{
      text-decoration: none;
  }
  
  .box{
      width:640px;
      height:426px;
      margin:100px auto;
      position: relative;
  }
  .pic_num>li{
      position: absolute;
      display: none;
  }
  .pic_num>li:first-child{
      display: block;
  }

/* 圆点*/
.num{
overflow: hidden;
position: absolute;
top:380px;
left:270px;
}
.num>li{
float:left;
width:15px;
height:15px;
border-radius: 50%;
background: #eee;
margin-left:5px;
}
.num>li:first-child{
background: #f00;
}

  button{
      width:30px;
      height:60px;
      position: absolute;
  }
  .prev{
      top:183px;
      
  }
  .next{
      top:183px;
      right:0;
  }

</style>
</head>
<body>
<script>
//自己动起来
//1.找到图片
//2.找到圆点
var picLi=document.querySelectorAll('.pic_num>li');
var numLi=document.querySelectorAll('.num>li');
var timer;
var i=0;

  function play(){
    timer=setInterval(function(){
          picLi[i].style.display='none';
          numLi[i].style.background='#eee';
          i++;
          if(i>4){
              i=0;
          }
          picLi[i].style.display='block';
          numLi[i].style.background='#f00';
        
      },1000)
  }

play();

  //给box添加鼠标移入移出事件
  var box=document.querySelector('.box');
  box.onmouseover=function(){
      clearInterval(timer);
  }
 box.onmouseout=function(){
      play();
  }

  //点击按钮
 var prev=document.querySelector('.prev');
 var next=document.querySelector('.next');
  
 next.onclick=function(){
    picLi[i].style.display='none';
    numLi[i].style.background='#eee';
     i++;
     if(i>4){
         i=0;
     }
     picLi[i].style.display='block';
     numLi[i].style.background='#f00';
 
 }
  
 prev.onclick=function(){
     picLi[i].style.display='none';
    numLi[i].style.background='#eee';
     i--;
     if(i<0){
         i=4;
     }
     picLi[i].style.display='block';
     numLi[i].style.background='#f00';
 }

//点击圆点切换
for(var j=0;j<numLi.length;j++){
numLi[j].index=j;
numLi[j].onclick=function(){
var num=this.index;
for(var a=0;a<numLi.length;a++){
picLi[a].style.display='none';
numLi[a].style.background='#eee';
}
picLi[num].style.display='block';
numLi[num].style.background="#f00";
}
}
</script>

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • CSS 轮播 *{padding:0;margin:0;list-style:none;} .box{ margi...
    dovlie阅读 2,563评论 0 0
  • 实现如下轮播效果(渐变轮播)task27-1 一个页面有3个轮播task-27-2 实现如下无限循环滚动轮播效果t...
    JunVincetHuo阅读 4,177评论 0 2
  • 轮播原生js封装 总共四个部分 标题 *{ margin:0; padding:0; } ul{ list-sty...
    小耗子不吃药阅读 1,661评论 0 0
  • 己所不欲勿施于人,你伤害了我,却还要我一笑而过? 想到了我小时候三年级的班主任,是语文老师,姓邹。那时我就感觉他不...
    斯洛克_阅读 1,117评论 0 0
  • 文/墨香依旧 “什么!你说的是真的!”西瓜一圆滚滚样的身躯从一张豪华的办公椅上弹了起来,又重重地落在了办公椅上,椅...
    计量青年杂志社阅读 3,008评论 2 3

友情链接更多精彩内容