web前端轮播图

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

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

    <title>Document</title>

    <style>

        .overall{

            width: 900px;

            height: 500px;

            align-items: center;

            margin: 5% auto;        

        }

        .content{

            position: relative;

            height: 400px;

        }

        .content ul{

            list-style-type: none;

        }

        .content ul>li{

            position: absolute;

            width: 600px;

            height: 300px;

            transition: 1s;

            opacity: 0;

        }

        .content ul>li img{

            width: 900px;

            height: 500px;

            border-radius: 5%;

            border: 5px solid pink;

        }

        .content ol{

            position: relative;

            display: grid;

            grid-template-columns: repeat(3, 75px);

            grid-template-rows: auto;

            grid-gap: 1em;

            gap:1em;

            float:right;

            margin-top: 450px;

            list-style: none;

            top: 0;

            left: 0;

        }

        .content ol li{

            width: 20px;

            height: 20px;

            font-size: 15px;

            line-height: 20px;

            float: left;

            text-align: center;

            border-radius: 2em;

            border: 5px solid black;

           

        }

    </style>

</head>

<body>

    <div class="overall">

        <div class="content">

            <ul>

                <li><img src="./电锯人 (16).00_00_00_28.Still001_00000.png" alt=""></li>

                <li><img src="./电锯人 (16).00_00_00_28.Still001_00038.png" alt=""></li>

                <li><img src="./电锯人 (17).00_00_00_28.Still001_00000.png" alt=""></li>

            </ul>

            <ol>

                <li></li>

                <li></li>

                <li></li>

            </ol>

        </div>        

    </div>

    <script>

    var content = this.document.getElementsByClassName("content")[0]

    var li = content.getElementsByTagName("li")

    function fun (i, j){

        li[i].style.opacity = 1

        li[j].style.opacity = 0

        li[i+3].style.backgroundColor = "black"

        li[j+3].style.backgroundColor = ""

    }

    fun(0, 1)

    var i = 0

    function auto(){

        i++

        if(i>=3){

            i=0

            fun(0,2)

        }

        else{

            fun(i, i-1)

        }

    }

    timer = this.setInterval(auto, 2000)

    content.onmouseover = function(){

        clearInterval(timer)

    }

    content.onmouseout = function(){

        timer = setInterval(auto, 2000)

    }

    for(j=0;j<3;j++){

        li[j+3].index = j

        li[j+3].onclick = function(){

            fun(this.index, i)

            i = this.index

        }

    }

    </script>

</body>

</html>

 

  • 20
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值