左右焦点轮播图

    <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;
        }


        .focused {
            position: relative;
            width: 100%;
            height: 100%;
        }

        #left,
        #right {
            z-index: 1;
            position: absolute;
            width: 35px;
            height: 60px;
            background-color: red;
            top: 50%;
            margin-top: -30px;
            background: rgba(0, 0, 0, .3);
            color: #fff;
            line-height: 60px;
            text-align: center;
            font-size: 25px;
            cursor: pointer;

        }

        #right {
            right: 0;
        }

    </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="focused">
            <span id="left">&lt;</span>
            <span id="right">&gt;</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;
    //获取两边焦点div
    var focused = inner.children[2];

    //显示和隐藏左右焦点
    box.onmouseover = function () {
        focused.style.display = "block";
    };
    box.onmouseout = function () {
        focused.style.display = "none";
    };
    var index = 0;
    //为左右焦点注册点击事件
    my$("right").onclick = function () {
        if (index < ulObj.children.length - 1) {
            index++;
            animate(ulObj, -index * imgWidth);
        }
    };

    my$("left").onclick = function () {
        if (index > 0) {
            index--;
            animate(ulObj, -index * imgWidth);
        }
    };

</script>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值