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() 方法的介紹,希望對大家有所幫助。