轮播图啊啊啊

html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<style>
    * {
        margin: 0;
        padding: 0;
    }


    #bigbox {
        overflow: hidden;
        width: 560px;
        height: 300px;
        margin-left: 600px;
    }

    #hidden {
        width: 11110px;
        height: 300px;
        display: flex;
        position: relative;
        flex-direction: row;
        display: inline-block;
        font-size:0 ;/*图片之间的缝隙消失*/
        
    }

    img {
        width: 560px;
        height: 300px;
        flex-shrink: 0;
    }

    #lt {
        z-index: 888;
        display: inline-block;
        margin-top: 0px;
        height: 300px;
        line-height: 300px;
        font-size: 20px;
        color: white;
        position: absolute;
        top: 0;
        flex-shrink: 0;
        display: none;
    }

    #gt {
        display: inline-block;
        left: 1140px;
        top: 0;
        height: 300px;
        line-height: 300px;
        font-size: 20px;
        position: absolute;
        color: white;
        flex-shrink: 0;
        display: none;
    }
</style>

<body>


    <div id="bigbox">
        <div id="lt">&lt;</div>
        <div id="hidden">
            
            <img src="https://ts2.cn.mm.bing.net/th?id=OIP-C.ja-L_FC01Xbzhqo4Rm3B8gHaEo&w=316&h=197&c=8&rs=1&qlt=90&o=6&dpr=1.5&pid=3.1&rm=2"
                alt="" id="img1">
            <img src="https://ts3.cn.mm.bing.net/th?id=OIP-C.sCLYtBNCTlCXHa7ujfRgBgHaGn&w=264&h=236&c=8&rs=1&qlt=90&o=6&dpr=1.5&pid=3.1&rm=2"
                alt="">
            <img src="https://ts3.cn.mm.bing.net/th?id=OIP-C.hZFCNMtSWiOwBv3jVI1ywAHaFj&w=288&h=216&c=8&rs=1&qlt=90&o=6&dpr=1.5&pid=3.1&rm=2"
                alt="">
                <img src="https://ts2.cn.mm.bing.net/th?id=OIP-C.ja-L_FC01Xbzhqo4Rm3B8gHaEo&w=316&h=197&c=8&rs=1&qlt=90&o=6&dpr=1.5&pid=3.1&rm=2"
                alt="" id="img1">

        </div>
        <div id="gt">&gt;</div>
    </div>
    <script src="./轮播图.js"></script>
</body>

</html>

js

var bigbox = document.querySelector("#bigbox")
var img = document.querySelector("img")
var img1 = document.querySelector("#img1")
var imgwidth = document.querySelector("img").offsetWidth
var hidden = document.querySelector("#hidden")
var lt = document.querySelector("#lt")
var gt = document.querySelector("#gt")



bigbox.onmouseover = function () {
    gt.style.display = "block"
    lt.style.display = "block"
    clearTimeout(timer)
}
bigbox.onmouseout = function () {
    gt.style.display = "none"
    lt.style.display = "none"
    lb()

}

let index = 0
lt.onclick = function () {
    if (index > 2) {
        index = 0
    }
    hidden.style.transiton = 5 + "s"
    index++
    var po = -560 * index
    left = po
    hidden.style.marginLeft = po + "px"

}
gt.onclick = function () {
    if (index > 1) {
        index = 0
    }
    hidden.style.transiton = 5 + "s"
    index++
    var qo = -560 * (index+1)
    left = qo
    hidden.style.marginLeft = qo + "px"

}

var left = 0
lb()
function lb() {
    hidden.style.transiton = "none"

    if (left < -1680) {
        left = 0
    }
    hidden.style.marginLeft = left + "px"
    var n = (left % 560 == 0&&left!=0) ? n = 3000 : n = 10
    left -= 10
    timer = setTimeout(lb, n)
}



  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值