我正在尝试自动滚动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>
有谁知道如何使此脚本将Div从左到右而不是从下到上移动?
顺便说一句,我对javascript很陌生,所以请保持温柔。
谢谢
最佳答案
您有两行代码表示dataobj.style.top="5px"
尝试将它们更改为dataobj.style.left="5px"
,看看是否可以解决。
编辑:dataobj.style.top=parseInt(dataobj.style.top)-scrollspeed+"px"
还需要将“顶部”更改为“左侧”。基本上,您的问题是,您正在更改错误的CSS属性。