代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
function move(flag)
{
if(flag == 1)
{
//滚动窗口内容到 偏移位置
window.scrollBy(20,0);
//window定时器,只会运行一次
timeout = setTimeout("move(1)",500);
}
else
if(flag == 2)
{
if(i>450)
i = 0;
//滚动窗口内容到 绝对位置
window.scroll(i,0);
i += 50;
}
}
function ss()
{
//和setTimeout不同,这个函数会周期运行,单位也是毫秒
interval=setInterval("move(2)",500);
}
</script>
</head>
<body>
<script>
window.defaultStatus = "这个属性现在大部分浏览器都不支持";
window.status = "只有opera还支持";
var timeout;
var interval;
var i = 0;
</script>
<form>
<input type="button" value="启动Time" οnclick="move(1);">
<input type="button" value="停止Time" οnclick="clearTimeout(timeout);">
<input type="button" value="启动Interval" οnclick="ss();">
<input type="button" value="停止Interval" οnclick="clearInterval(interval);">
</form>
<pre>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</pre>
</body>
</html>