您的位置:首页 > 其它

无聊时用动态原型改写的一个不间断向上滚动

2009-01-11 00:35 369 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>不间断向上滚动代码(无聊时用动态原型改写的)</title>

<script>

<!--

var i=0;

function $(ID)

{

var obj=document.getElementById(ID);

return obj;

}

function moveup(id,heigth)

{

this.id=id;

$(this.id+2).innerHTML=$(this.id+1).innerHTML

if(typeof(moveup._initialized=="undefined"))

{

moveup.prototype.move=function()

{

if($(this.id+2).offsetHeight-$(this.id).scrollTop<=0)

{

$(this.id).scrollTop-=$(this.id+1).offsetHeight;

}

else{

$(this.id).scrollTop++;

}

}

moveup._initialized=true;

}

}

-->

</script>

<style>

.demo{

width:400px;

height:20px;

background:#FF0000;

OVERFLOW: hidden;

padding:0px;

margin:0px;

}

.demo1{

width:400px;

padding:0px;

margin:0px;

}

</style>

</head>

<body>

<div id="demo" class="demo">

<div id="demo1" class="demo1">

1<br />

2<br />

3<br />

4<br />

5<br />

</div>

<div id="demo2"></div>

</div>

<script>

var rollspeed=100;

var obj=new moveup("demo",25);

var t=setInterval("obj.move()",rollspeed);

$("demo").onmouseover=function() {clearInterval(t)}//鼠标移上时清除定时器达到滚动停止的目的

$("demo").onmouseout=function() {t=setInterval("obj.move()",rollspeed)}//鼠标移开时重设定时器

</script>

</body>

</html>

以上代码只要把

if($(this.id+2).offsetHeight-$(this.id).scrollTop<=0)

{
$(this.id).scrollTop-=$(this.id+1).offsetHeight;

}
else{

$(this.id).scrollTop++;
}

里的scrollTop改为scrollLeft

offsetHeight改为offsetWidth就可以改为向左或向右滚动了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: