2011-02-16 108 views

回答

8

您可以在window.onload元素上使用scrollIntoView事件..

在你的情况,你会做:

window.onload = function() { 
    var el = document.getElementById('target'); 
    el.scrollIntoView(true); 
} 

良好的文档可以在这里找到: MDN scrollIntoView

2

你的身体标签也更改为类似

<body onload="ScrollToTarget"> 

那么你的功能,可以在头被定义为

function ScrollToTarget() 
{ 
    document.getElementById("target").scrollIntoView(true); 
}