简单的轮播图

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

        img {
            vertical-align: top;
        }

        .box {
            width: 730px;
            height: 454px;
            margin: 100px auto;
            padding: 5px;
            border: 1px solid #ccc;
            background-color: #cccccc;

        }

        .inner {
            width: 730px;
            height: 454px;
            background-color: aliceblue;
            overflow: hidden;
            position: relative;
        }

        .inner ul {
            width: 1000%;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 1;
        }

        .inner li {
            float: left;
            list-style: none;
        }

        .square {
            width: 135px;
            height: 20px;
            background-color: yellow;
            background: rgba(0, 0, 0, .3);
            border-radius: 10px;
            position: absolute;
            left: 50%;
            margin-left: -60px;
            bottom: 10px;
            z-index: 1;
        }

        .square span {
            float: left;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin: 4px 5px;
            display: inline-block;
            cursor: pointer;
            background-color: #fff;
            text-align: center;
            line-height: 16px;
        }

        .square .current {
            background-color: yellow;
            color: gray;
        }
        
    </style>
<div class="box" id="box">
    <div class="inner">
        <ul>
            <li><a href="#"><img src="img/1.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/2.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/3.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/4.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/5.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/6.jpg" alt=""></a></li>
        </ul>
        <div class="square">
            <span class="current"></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
        </div>
    </div>
</div>
<script>
    //获取最外面的div
    var box = my$("box");
    //获取相框
    var inner = box.children[0];
    //获取相框宽度
    var imgWidth = inner.offsetWidth;
    //获取ul
    var ulObj = inner.children[0];
    //获取span
    var spanObjs = inner.children[1].children;


    //循环遍历span,注册鼠标进入事件
    for (var i = 0; i < spanObjs.length; i++) {
     //循环的时候把索引值保存在每个span的自定义属性中
     spanObjs[i].setAttribute("index", i);
     //注册事件
     spanObjs[i].onmouseover = function () {
     //设置鼠标移入的样式
     for (var j = 0; j < spanObjs.length; j++) {
     spanObjs[j].removeAttribute("class");
     }
     this.className = "current";

     //移动ul(每个图片的宽*鼠标放在当前按钮的索引值)
     //获取索引
     var index = this.getAttribute("index");
     animate(ulObj, -index * imgWidth);
     };
     }

</script>

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值