无缝滚动代码,滚一次就停止了。

<div>
                    <div id="div_right">
                        <span id="btn_left" onmousemove="showmar()" class="arrow_next"></span>
                    </div>
                    <div id="starScroll">
                        <div id="contentScroll">
                            <div id="ScrollOne">
                                <a href="list_details.html?id=19398" ><img src="ypImgs/index/1.png" /></a>
                                <a href="list_details.html?id=31185" ><img src="ypImgs/index/2.png" /></a>
                                <a href="list_details.html?id=13694" ><img src="ypImgs/index/3.png" /></a>
                                <a href="list_details.html?id=19398" ><img src="ypImgs/index/4.png" /></a>
                                <a href="list_details.html?id=31185" ><img src="ypImgs/index/5.png" /></a>
                                <a href="list_details.html?id=13694" ><img src="ypImgs/index/6.png" /></a>
                            </div>
                            <div id="ScrollTwo"></div>
                        </div>
                    </div>
                    <div id="div_left">
                        <span id="btn_right" onmousemove="showmar()" class="arrow_prev"></span>
                    </div>

                </div>


                var Scroll=(function(){
            return function(){
                var starScroll = document.getElementById("starScroll"),
                        ScrollOne = document.getElementById("ScrollOne"),
                        aCollection = ScrollOne.getElementsByTagName("a"),
                        aLength = aCollection.length,
                        ScrollTwo = document.getElementById("ScrollTwo"),
                        btn_left = document.getElementById("btn_left"),
                        btn_right = document.getElementById("btn_right");
                var Width = 231,Current = 1,Rate = 7,TimeTimeout=2000,TimeInterval=10,MarginRight=0;
                var SInterval=null,STimeout=null;
                var flag=true;
                        function ScrollLeft(){
                    var CountWidth = Current*Width+Current*MarginRight,
                            SLeftPara=starScroll.scrollLeft;
                    if(ScrollTwo.offsetWidth-SLeftPara==0){
                        starScroll.scrollLeft=0;
                        Current=0;
                    }
                    if(CountWidth-SLeftPara==0){
                        Forward();
                    }
                    else{
                        var v = Math.round((CountWidth-SLeftPara)/Rate);
                        v = v<1 ? 1 : v;
                        SetScrollLeft(SLeftPara+v);
                    }
                }
                function SetScrollLeft(scrollleft){
                    starScroll.scrollLeft=scrollleft;
                }
                function Init(){
                    flag=false;
                    SInterval=setInterval(ScrollLeft,TimeInterval);
                }
                function Forward(){
                    clearInterval(SInterval);
                    Current++;
                    flag=true;
                    STimeout = setTimeout(Init,TimeTimeout);
                }
                btn_right.onclick=function(){
                    if(flag){
                        clearTimeout(STimeout);
                        Init();
                    }
                }
                function ScrollRight(){
                    var CountWidth = Current*Width+Current*MarginRight,
                            SLeftPara = starScroll.scrollLeft;
                    if(CountWidth-SLeftPara==0){
                        Forward();
                    }
                    else{
                        var v = Math.round((CountWidth-SLeftPara)/Rate);
                        v = v>-1?-1:v;
                        SetScrollLeft(SLeftPara+v);
                    }
                }
                btn_left.onclick=function(){
                    if(!flag){
                        return;
                    }
                    flag=false;
                    clearTimeout(STimeout);
                    if(Current==1){
                        SetScrollLeft(ScrollTwo.offsetWidth);
                        Current=aLength+1;
                    }
                    Current-=1;
                    SInterval = setInterval(ScrollRight,TimeInterval);
                }
                if(aLength>0){
                    starScroll.scrollLeft=0;
                    ScrollTwo.innerHTML = ScrollOne.innerHTML;
                    STimeout = setTimeout(Init,TimeTimeout);
                }
            }
        })();
        Scroll();

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



无标题文档 *{margin:0; padding:0; list-style:none;} .con{width:600px;height:200px;border:1px solid #000; margin:100px auto;position:relative;overflow:hidden;} .con ul {width:1800px;position:absolute;left:0;top:0;} .con ul li{width:300px;height:200px;float:left;} .Btn{width:600px;text-align:center;margin:0 auto;} $(function(){ var num = 0; var gun = -3;//控制方向,值为-3是向左,值为3时向右走,默认向左走 var myFn = function(){ num += gun; if(num < -1200){ num = 0; }else if(num > 0){ num = -1200; } $('.con ul').css('left',num + 'px'); } var myClone = $('.con ul li:eq(0),.con ul li:eq(1)').clone(true); //克隆第一二个li var myTag = $(myClone); $('.con ul').append(myTag); //将克隆好的li添加到ul最后位置 var timer01 = null; timer01 = setInterval(myFn,30);//默认情况下向左走 $('button').eq(0).click(function(e) { //点击向左走后开始向左走 gun = -3; }); $('button').eq(1).click(function(e) { //点击向右走后开始向右走 gun = 3; }); $('.con ul li').hover(function(e) { clearInterval(timer01); $(this).siblings().stop().fadeTo(300,0.5); },function(){ clearInterval(timer01); timer01 = setInterval(myFn,30) $(this).siblings().stop().fadeTo(300,1); }); })











向左走 向右走