8.4

作者: 小豪豪豪豪豪豪 | 来源:发表于2018-08-20 09:59 被阅读0次

轮播

<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>

相关文章

  • 8.4

    轮播 /* 圆点*/.num{overflow: hidden;position: absolute...

  • 8.4

    今天又是特别不好的一天 在反复的自责中 反复痛苦 我好累 好怕自己撑不下去 可是我不知道该和谁说 不敢张口 为什么...

  • 8.4

    今天坐火车回保定,早上四点钟起床往武昌赶,结果原本七点整的火车,晚点到九点半才出发,中途刘波打来电话,问我最近的财...

  • 8.4

    英语半小时 秋华总长PPT

  • 8.4

    今天赌了一把,希望不会被骗,希望一切如愿。

  • 8.4

    生存挑战第13天: 今天上午我自己一个人卖出去一瓶货,然后一直到下午就再也没有卖出去。很多人都说,我买过了...

  • 8.4

    今天打电话第一次邀约,挺紧张的,不过后来慢慢顺手啦。 最另我意外的是,我预售三个多月加的一千多资源里面唯一一个我删...

  • 8.4

    明天上班班啦,激动激动激动

  • 8.4

    感觉又是一个不眠夜,小红劝我好好准备考试,不要上班。老师,公务员,总要走一条路。 如果今年考上,就...

  • 8.4

    今天打电话打的挺顺利的 一步一步走好吧!晚安!

网友评论

      本文标题:8.4

      本文链接:https://www.haomeiwen.com/subject/jmdkiftx.html