DIV CSS 佈局教程網

淺談 window 物件的 scrollBy() 方法
編輯:關於JavaScript     

scrollBy() 方法的定義與用法如下。

語法結構

scrollBy(x, y)

此方法可把內容移動指定尺寸,單位為像素(px)。

參數列表:
x 必要,內容向右移動的尺寸;
y 必要,內容向下移動的尺寸。

瀏覽器支援

IE、Firefox、Opera、Chrome 均支援此方法。

程式碼實例

 <!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
 <title></title>
 <style>
 *{ margin:0px; padding:0px; }
 body{ width:1800px; height:1200px; }
 input{ position:fixed; left:20px; top:20px; }
 </style>
 <script type="text/javascript">
 function resize(){
 window.scrollBy(200,300);
 }
 window.onload=function(){
 var bt=document.getElementById("bt");
 bt.onclick=function(){ resize() }
 }
 </script>
 </head>
 <body>
 <input type="button" value="查看效果" id="bt">
 </body>
 </html>

點擊按鈕後,頁面內容就會向右移動 200px、向下移動 300px。以上就是 scrollBy() 方法的介紹,希望對大家有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved