js 实现无缝隙滚屏

页面代码

.scroll{
            overflow:hidden;
            position:relative;
        }
.scroll li{
            line-height:20px;
            position:absolute;
            
        }
        


<div class="scroll" style="height:240px;">
<ul>

<li style="top:0">1111111111111</li>
<li style="top:20px">22222222222</li>
<li style="top:40px">33333333333</li>
<li style="top:60px">44444444444</li>
<li style="top:80px">55555555555</li>
<li style="top:100px">66666666666</li>
                                
</ul>
</div>

js代码

<script type="text/javascript">
            $(function(){
                var lis=$(".scroll li");
                gun=setInterval(function() {
                    $.each(lis,function(index,li){
                    var list=$(li);
                    var height=parseFloat(list.css("lineHeight");
                    var top=parseFloat(list.css("top"));
                    list.css("top",top-1);
                    if(top<-height){
                        var bottom=(lis.length-1)*height;
                        list.css("top",bottom)
                    }
                });
                }, 50)
                //停止滚动
                var div=$(".scroll ul");
                div.hover(function(){
                    clearInterval(gun)
                },function(){
                    gun=setInterval(function() {
                    $.each(lis,function(index,li){
                    var list=$(li);
                    var height=parseFloat(list.css("lineHeight");
                    var top=parseFloat(list.css("top"));
                    list.css("top",top-1);
                    if(top<-height){
                        var bottom=(lis.length-1)*height;
                        list.css("top",bottom)
                    }
                });
                }, 50)
                });
            });

转载于:https://www.cnblogs.com/jianglei233/p/7778315.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值