4
我是後端開發人員,JavaScript新手。任何人都可以提供稿件的幾行字,讓該頁面自動滾動到「目標」元素在頁面加載後需要javascript自動滾動到頁面加載後的目標html元素
<html>
<bod>
<p id="target">...</p> // auto-scroll here
</bod>
</html>
感謝
我是後端開發人員,JavaScript新手。任何人都可以提供稿件的幾行字,讓該頁面自動滾動到「目標」元素在頁面加載後需要javascript自動滾動到頁面加載後的目標html元素
<html>
<bod>
<p id="target">...</p> // auto-scroll here
</bod>
</html>
感謝
您可以在window.onload元素上使用scrollIntoView事件..
在你的情況,你會做:
window.onload = function() {
var el = document.getElementById('target');
el.scrollIntoView(true);
}
良好的文檔可以在這裏找到: MDN scrollIntoView
你的身體標籤也更改爲類似
<body onload="ScrollToTarget">
那麼你的功能,可以在頭被定義爲
function ScrollToTarget()
{
document.getElementById("target").scrollIntoView(true);
}
能否請您標誌着一個正確的答案。 – hitautodestruct 2014-01-01 09:51:36