JS原生代码写轮播图

<!DOCTYPE html>

<html lang="en">



<head>

    <meta charset="UTF-8">

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

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

    <title>第五题</title>

    <style>

        .content {

            width: 400px;

            height: 400px;

            margin: 0 auto;

            position: relative;

            overflow: hidden;

            border: 1px solid black;

        }



        .box {

            width: 1200px;

            height: 400px;

        }



        .box1 {

            width: 400px;

            height: 400px;

            float: left;

            background-color: rgb(130, 243, 111);

        }



        .box2 {

            width: 400px;

            height: 400px;

            background-color: cadetblue;

            float: left;

        }



        .box3 {

            width: 400px;

            height: 400px;

            background-color: rgb(238, 129, 102);

            float: left;

        }

    </style>

</head>



<body>

    <div class="content">

        <div class="box">

            <div class="box1">第一页</div>

            <div class="box2">第二页</div>

            <div class="box3">第三页</div>

        </div>

    </div>

</body>

<script>

    window.onload = function () {

        var box = document.querySelector(".box");

        var num = 0;

        setInterval(function () {

            num++;

            var boxlen = 0;

            if (num == 3) {

                num = 0;

                boxlen = 0

            }

            else {

                boxlen = num * 400

            }

            console.log(num)

            box.style.cssText = "transform: translate3d(-" + boxlen + "px,0,0);transition : 1000ms";

        }, 3000);

     }

</script>

</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值