上下无缝轮播

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body,ul,li,img{
            margin: 0;
            padding: 0;
        }
        li{
            list-style: none;
        }
        #box{
            width: 500px;
            height: 300px;
            position: relative;
            margin: 100px auto;
            border: 1px solid #000;
            overflow: hidden;
        }
        #ul_1{
            width: 500px;
            height: 300px;
            position: absolute;
        }      
        img{
             display: block;
             width: 500px;
             height: 300px;
             border: 0;
         }
        #box>div{
            width: 50px;
            height: 50px;
            background: rgba(0,0,0,0.5);
            text-align: center;
            color: #fff;
            line-height: 50px;
            font-size: 50px;
            cursor:pointer;
            right: 10px;
        }
        #top_{
            position: absolute;
            top: 110px;
        }
        #bottom_{
            position: absolute;
            top: 170px;
        }
        #ul_2{
            position: absolute;
            bottom: 10px;
            left: 200px;
            margin: auto;
        }
        #ul_2>li{
            float: left;
            width: 10px;
            height: 10px;
            border: 1px solid #fff;
            border-radius: 50%;
            margin: 0 10px;
        }
        #ul_2>li:hover,#ul_2 .hover{
            background: #fff;
        }
    </style>
</head>
<body>
    <div id="box">
        <ul id="ul_1">
            <li><img src="imgs/img1.jpg"></li>
            <li><img src="imgs/img2.jpg"></li>
            <li><img src="imgs/img3.jpg"></li>
            <li><img src="imgs/img1.jpg"></li>
        </ul>
        <ul id="ul_2">
            <li class="hover"></li>
            <li></li>
            <li></li>
        </ul>
        <div id="top_" >&blacktriangle;</div>
        <div id="bottom_">&blacktriangledown;</div>
    </div>
    <script src="jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
    <script> 
        $(function(){    
            var i = 0;
            //设置计数
            var timer = setInterval(move,3000);
            //每3秒动一次
            
            function move() {
                i++;
                if(i==$("#ul_1 li").length){
                    $("#ul_1").css("top",0);
                    i=1;                    
                }                                
                if(i == -1 ){
                    $("#ul_1").css("top",-$("#ul_1 li").outerHeight()*($("#ul_1 li").length-1));                   
                    i = $("#ul_1 li").length - 2;
                }
                
                if(i == $("#ul_1 li").length-1){
                    $("#ul_2 li").eq(0).addClass("hover").siblings().removeClass("hover");                   
                   }else {                    
                    $("#ul_2 li").eq(i).addClass("hover").siblings().removeClass("hover");
                }  
                
                $("#ul_1").css("height",$("#ul_1 li").outerHeight()*$("#ul_1 li").length);
                $("#ul_1").stop().animate({"top":$("#ul_1 li").outerHeight()*-i},1000);               
            }
            
            for(let a=0;a<$("#ul_2 li").length;a++){           
               $("#ul_2 li").eq(a).mouseover(function () { 
                      $("#ul_2 li").eq(a).addClass("hover").siblings().removeClass("hover");
                   i = a - 1;
                   move();
               })
            }
            
            $("#top_").click(function(){
                move();
            });
            $("#bottom_").click(function(){
                i = i-2;           
                move();
            });
            $("#box").mouseover(function () {
                clearInterval(timer);
            });
            $("#box").mouseout(function () {
                 timer = setInterval(move,3000);
            });  
        })
       
    </script>
</body>
</html>

转载于:https://my.oschina.net/u/3873061/blog/1848914

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值