轮播图

<!DOCTYPE html>
<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;
        }
        .body{
            margin:0 auto;
            width: 1300px;
            overflow: hidden;
            position: relative;
            height: 400px;
            background-color: yellow;
        }
        .img{
            width: 999999px;
            height: 400px;
            overflow: hidden;
            position: absolute;
            /* left: -1300px; */
        }
        .img li img{
            width: 1300px;
            height: 400px;
            float: left;
        }
        li{
            list-style-type: none;
        }
        .prev,.next{
            position:absolute;
            width: 32px;
            height: 32px;
            top: 50%;
        }
        .prev{
            background-image: url(./img/prev.png);
            left: 40px;
        }
        .next{
            background-image: url(./img/next.png);
            right: 40px;
        }
        .count{
            position: absolute;
            width: 60px;
            height: 10px;
            margin: 0 auto;
            bottom: 25px;
            /* background-color: black; */
            left: 612px;
        }
        .count li a{
            width: 10px;
            height: 10px;
            cursor:pointer; /* 将鼠标形状设为手形 */
            background-color:#ccc;
            opacity: .5;/*不透明度,取值范围:[0,1]之间的一个数,可以是小数*/
            float: left;
            margin-left: 5px;
            border-radius: 50%;/*圆角*/
        }
        .count .active{
            background-color: slateblue;
            opacity: 1;
        }
    </style>
</head>
<body>
    <div class="body">
        <ul class="img">
            <li><img src="./img/banner_01.jpg" alt="介绍"></li>
            <li><img src="./img/banner_02.jpg" alt="介绍"></li>
            <li><img src="./img/banner_03.jpg" alt="banner"></li>
        </ul>
        <div class="control">
            <div class="prev"></div>
            <div class="next"></div>
        </div>
        <!-- 计数器 -->
        <ul class="count">
            <li><a class="active" href="javascript:;"></a></li>
            <li><a href="javascript:;"></a></li>
            <li><a href="javascript:;"></a></li>
        </ul>
    </div>
</body>
<script>
    let allA = document.getElementsByTagName('a')
    let allImg = document.getElementsByClassName('img')[0]
    let img = allImg.getElementsByTagName('img')[0]
    let width = getComputedStyle(img,null)['width']
    for(i in allA){
        allA[i].num = i
        allA[i].onclick = function () {
            for(j in allA){   //此处用for/in会报错 因为会遍历到非枚举型属性
                /* this.style.backgroundColor = '#ccc' */
                
                console.log(allA.hasOwnProperty(j))
            }
            this.style.backgroundColor = 'blue'
            alert((-parseInt(width))*this.num +'px')
            allImg.style.left = (-parseInt(width))*this.num +'px'

        }
    }
    
</script>
</html>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值