亲宝软件园·资讯

展开

用js实现控制内容的向上向下滚动效果

人气:0
<SCRIPT language=JavaScript1.2>
iens6=document.all||document.getElementById
ns4=document.layers

//specify speed of scroll (greater=faster)
var speed=10

if (iens6){
document.write('<div id="container" style="position:relative;width:600;height:430;border:0px solid black;overflow:hidden">')
document.write('<div id="content" style="position:absolute;width:590;left:0;top:0">')
}
</SCRIPT>
<SCRIPT language=JavaScript1.2>
if (iens6)
document.write('</div></div>')
</SCRIPT>
<SCRIPT language=JavaScript1.2>
if (iens6){
var crossobj=document.getElementById? document.getElementById("content") : document.all.content
var contentheight=crossobj.offsetHeight
}
else if (ns4){
var crossobj=document.nscontainer.document.nscontent
var contentheight=crossobj.clip.height
}

function movedown(){
if (iens6&&parseInt(crossobj.style.top)>=(contentheight*(-1)+100))
crossobj.style.top=parseInt(crossobj.style.top)-speed
else if (ns4&&crossobj.top>=(contentheight*(-1)+100))
crossobj.top-=speed
movedownvar=setTimeout("movedown()",100)
}

function moveup(){
if (iens6&&parseInt(crossobj.style.top)<=0)
crossobj.style.top=parseInt(crossobj.style.top)+speed
else if (ns4&&crossobj.top<=0)
crossobj.top+=speed
moveupvar=setTimeout("moveup()",100)

}

function getcontent_height(){
if (iens6)
contentheight=crossobj.offsetHeight
else if (ns4)
document.nscontainer.document.nscontent.visibility="show"
}
window.onload=getcontent_height
</SCRIPT>

加载全部内容

相关教程
猜你喜欢
用户评论