jquery广告无缝轮播代码实例

jquery广告无缝轮播代码实例

需要自行添加五张图片和引用jquery库

纵向轮播实例:

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

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>jquery广告无缝轮播演示</title>
        <script src="../js/jquery-1.12.4.js"></script>
        <style type="text/css">
            li {
                list-style: none;
                width: 380px; 
                height: 180px; 
                float: left;
            }
            img {
                height: 180px;
                width: 380px;
            }
            ul{
                position: relative;
                height: 180px;
                width: 380px;
                top: 0px;
                padding: 0;
                margin: 0;
            }
            .divFollow a{
                background-color: #FFFFFF;
                width: 18px;
                height: 5px;
                display: inline-block;
            }
            .mains .title {
                font-size: 25px;
            }
            .g1 {
                width: 380px;
                height: 180px;
                margin: 0 auto;
                overflow: hidden;
            }
            #bb{
                width: 380px;
                height: 180px;
                position: relative;
            }

        </style>
    </head>

    <body>
        <div class="mains">
            <div class="title">jquery广告无缝轮播演示</div>
            <div class="g1">
                <ul id="ulID">
                    <li><img src="../img/1.jpg"></li>
                    <li><img src="../img/2.jpg"></li>
                    <li><img src="../img/3.jpg"></li>
                    <li><img src="../img/4.jpg"></li>
                    <li><img src="../img/5.jpg"></li>
                    <li><img src="../img/1.jpg"></li>
                </ul>
            </div>
        </div>
        <script type="text/javascript">
            var PlaceTop = parseInt($("#ulID").css("top"));
            function moveUL() {
                var ulID = $("#ulID");
                PlaceTop = --PlaceTop;
                if(PlaceTop == -916) {
                    PlaceTop = -17;
                }
                ulID.css("top", PlaceTop);
                if(PlaceTop < -916) {
                    alert("Eror!");
                    clearInterval(int);
                }
            }
            int = setInterval("moveUL()", 10);
            $(".g1").hover(function() {
                clearInterval(int);
            }, function() {
                int = setInterval("moveUL()", 10);
            });
        </script>
        <br>
        <div style="text-align: center;overflow: hidden;width: 380px;height: 180px;margin: 0 auto;">
            <div id="bb" style="display: inline-block;left:0px;">
                <img style="left:0px;position: absolute;" src="../img/1.jpg" />
                <img style="left:-380px;position: absolute;" src="../img/2.jpg" />
                <img style="left:-760px;position: absolute;" src="../img/3.jpg" />
                <img style="left:-1140px;position: absolute;" src="../img/1.jpg" />
            </div>
            <div id="bbFollow" class="divFollow" style="position: absolute;margin-top: -33px;width: 365px;text-align: right;">
                <a></a>
                <a></a>
                <a></a>
            </div>
        </div>
        <script type="text/javascript">
            var moveId = $("#bb")
            var PlaceLeft = parseInt(moveId.css("left"));
            var intval;
            var follow = 0;
            var cicleTime = 18;
            function moveImg() {
                PlaceLeft = ++PlaceLeft;
                if(PlaceLeft == 1140) {
                    PlaceLeft = 0;
                }
                follow = parseInt(PlaceLeft / 380);         
                if (follow > 2) {
                    follow = 0;
                }
                //小图
                $("#bbFollow a").each(function (index) {
                    if (follow == index) {
                        $(this).css("background-color", "#f6de09")
                    } else {
                        $(this).css("background-color", "#fff")
                    }
                })
                moveId.css("left", PlaceLeft);
            }
            intval = setInterval("moveImg()", cicleTime);
            $("#bb").hover(function() {
                clearInterval(intval);
            }, function() {
                intval = setInterval("moveImg()", cicleTime);
            });

        </script>
    </body>

</html>

效果截图:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值