js轮播图

最垃圾的轮播图

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <style>

        *{

            margin: 0;

            padding: 0;

        }

        div{

            position: relative;

        margin: 0 auto;

     

        }

        body{

            z-index: 10000;        

        }

        ul{

            list-style: none;

            display: flex;

            position: relative;

           

        }

        .one>li{

            width: 500px;

            height: 300px;

            position: absolute;

            left: 50%;

            margin-left:-250px;

        }

        .one>:nth-last-child(4){

            background-color: blanchedalmond;

        }

        .one>:nth-last-child(3){

            background-color: rgb(73, 3, 186);

        }

        .one>:nth-last-child(2){

            background-color: rgb(102, 4, 70);

        }

        .one>:nth-last-child(1){

            background-color: rgb(3, 88, 0);

           

        }

        .one>:nth-last-child(5){

            background-color: rgb(211, 203, 203);

           

        }

        .one>:nth-last-child(6){

            background-color: rgb(147, 0, 0);

         

        }

       .qq{

        z-index: 1;

       }

       #long{

        width: 25px;

        height: 80px;

        position: absolute;

            left: 50%;

            margin-left:225px;

            margin-top: 110px;

            z-index: 1000000000;

            opacity: 0.5;

       }

       #mong{

        width: 25px;

        height: 80px;

        position: absolute;

            left: 50%;

            margin-left:-250px;

            margin-top: 110px;

            z-index: 1000000000;

            opacity: 0.5;

       }

       .two{

        z-index: 544455448848;

       width: 250px;

       height: 120px;

       margin: 0 50%;

       margin-top: 250px;

     

       }

       .two>li{

      width: 20px;

      height: 20px;

      border: 1px solid violet;

      border-radius: 50%;

    margin-left: 12px;

   background-color: black;

       }

    </style>

</head>

<body>

    <div class="">

        <ul class="one">

            <li class="oo  qq">0</li>

            <li class="oo">1</li>

            <li class="oo">2</li>

            <li class="oo">3</li>

            <li class="oo">4</li>

            <li class="oo">5</li>

        </ul>

        <button id="long" οnclick="one()">></button>

        <button id="mong" οnclick="two()"><</button>

    </div>

    <ul class="two">

        <li class="jong"></li>

        <li class="jong"></li>

        <li class="jong"></li>

        <li class="jong"></li>

        <li class="jong"></li>

        <li class="jong"></li>

    </ul>

</body>

<script>

    var ul= document.getElementsByClassName('oo')

    var long = document.getElementById('long')

    var mong = document.getElementById('mong')

    var jongs = document.getElementsByClassName('jong')

    var bodys = document.getElementsByTagName("div")

    var i =0;

    var p= 2

    //左切换

  function one(){

   

   if(i<ul.length-1){

    i++

    ul[i].style.zIndex=p

    console.log('i'+i);

    console.log(p)

    p++

  }else if(i=ul.length-1){

        i=0

        ul[i].style.zIndex=p

    console.log(i);

    console.log(p)

    p++

  }

  }

  //右切换

  function two(){

   

if(i!=0){

   

    i--

    ul[i].style.zIndex=p

    p++

}else{

    i=ul.length-1

ul[i].style.zIndex=p

p++

}

  }


 

  //自动轮播

    var aaa=setInterval('one()',1500)


 

//    console.log(jongs);

   for (var u = 0, len = jongs.length; u < len; u++) {

  (function (j) {

    //点圆点切换对应的图

    jongs[j].onclick = function () {

        p++

        ul[j].style.zIndex=p

        console.log(p);

    }

    var  ppo=2

   

    //点击停止自动轮播

  if(ppo%2==0){

        ppo++

        ul[j].onclick = function(){

    clearInterval(aaa)

    // console.log(ppo);

   

    } }

  })(u)

}



 

</script>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

箱子?

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值