本實(shí)例實(shí)現(xiàn)在打開頁面,當(dāng)頁面出現(xiàn)縱向滾動(dòng)條時(shí),頁面中的內(nèi)容將從上向下進(jìn)行滾動(dòng)。
本例主要是使用 window 對(duì)象的 scroll()方法指定窗口的當(dāng)前位置。下面對(duì) scroll()方法進(jìn)行詳細(xì)說明。
scroll()方法的語法格式:
scroll(x,y);
參數(shù)說明如下。
功能:指定窗口滾動(dòng)坐標(biāo)的位置。
用于實(shí)現(xiàn)功能的主頁面 index.html。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
var position = 0;
function scroller()
{
if(true)
{
position++;
scroll(0,position);
clearTimeout(timer);
var timer = setTimeout("scroller()",10);
}
}
scroller();
</script>
</head>
<body>
<img src="new.jpg"/><br/>
<img src="new.jpg"/><br/>
<img src="new.jpg"/><br/>
<img src="new.jpg"/><br/>
</body>
</html>