2013-02-26 132 views
0

我想要自动滚动一个Div,而不是从顶部到底部或从底部到顶部,我需要它从左到右!自动滚动Div从左到右?

我发现了一个完全符合我需要的代码,但它只是自下而上。

这是代码:

<script type="text/javascript"> 

/*********************************************** 
* IFRAME Scroller script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) 
* This notice MUST stay intact for legal use 
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code 
***********************************************/ 

//Specify speed of scroll. Larger=faster (ie: 5) 
var scrollspeed=cache=2 

//Specify intial delay before scroller starts scrolling (in miliseconds): 
var initialdelay=500 

function initializeScroller() { 
    dataobj = document.all? document.all.datacontainer : 
          document.getElementById("datacontainer") 
    dataobj.style.top = "5px" 
    setTimeout("getdataheight()", initialdelay) 
} 

function getdataheight() { 
    thelength=dataobj.offsetHeight 
    if (thelength == 0) 
     setTimeout("getdataheight()",10) 
    else 
     scrollDiv() 
} 

function scrollDiv() { 
    dataobj.style.top=parseInt(dataobj.style.top)-scrollspeed+"px" 
    if (parseInt(dataobj.style.top) < thelength*(-1)) 
     dataobj.style.top = "5px" 
    setTimeout("scrollDiv()",40) 
} 

if (window.addEventListener) 
    window.addEventListener("load", initializeScroller, false) 
else if (window.attachEvent) 
    window.attachEvent("onload", initializeScroller) 
else 
    window.onload=initializeScroller 

</script> 

有谁知道如何使这个脚本移动事业部左右,而不是底部到顶部?顺便说一句,我对JavaScript很新,所以请温柔一点。

感谢

回答

3

您有两行代码说dataobj.style.top="5px"尝试改变他们dataobj.style.left="5px",看看能否解决。

编辑:dataobj.style.top=parseInt(dataobj.style.top)-scrollspeed+"px"也需要将“顶部”更改为“左侧”。基本上,你的问题是,你正在改变错误的CSS属性。

+0

做到了。非常感谢。 – user2056633 2013-02-26 00:21:07

+0

不客气,祝你的项目好运。 – 2013-02-26 00:22:09