不间断连续滚动,文字图片都可以

<html> 
<head> 
<base href="http://keleyi.com"> 
<title></title><base target="_blank" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<style>
    *{ margin:0; padding:0;}
    #photo-list{ width:980px; height:400px; margin:0 auto; overflow:hidden;}
    ul{ width:9999px; height:400px;}
    ul li{height:400px;width:980px; display:inline-block;list-style-type:none; float:left;}
    .one{ background:#f0b8b8;}
    .two{ background:#eef0b8;}
    .three{ background:#b8f0d7;}
    .fore{ background:#b8e1f0;}
</style>
</head> 
<body> 
    <div id="photo-list">
        <ul id="scroll">
            <li class="one"></li>
            <li class="two"></li>
            <li class="three"></li>
            <li class="fore"></li>
        </ul>
    </div>
<script>
    $(function ()
    {
        var c = $('#photo-list');
        var ul = $('#scroll'),
           itemCount = $("li").length,
           width = $("li").width(), //获得每个img容器的宽度
           scrollLeft = 0,
           marquee = function ()
           {
               c.scrollLeft(scrollLeft);
               scrollLeft += 2;
               if (scrollLeft % width <= 1)
               {  //当 c.scrollLeft 和 width 相等时,把第一个img追加到最后面
                   var htm = $("li").first().clone();
                   ul.append(htm);
                   $("li").first().remove();
                   scrollLeft = 0;
               };
           },
           speed = 20; //数值越大越慢
        $('#scroll').width(width * itemCount + 'px'); //加载完后设置容器长度        
        var timer = setInterval(marquee, speed);
    })
</script>
</body> 
</html>

 

转载于:https://www.cnblogs.com/wwqianduan/p/3542603.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值