javascript 在底部加载 HTML 页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7699941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Html page load at the bottom
提问by Luke
I need an HTML page to automatically scroll down when the page loads. So basically loads at the bottom. Can JavaScipt be used?
我需要一个 HTML 页面在页面加载时自动向下滚动。所以基本上加载在底部。可以使用 JavaScipt 吗?
Please can you help me or lead my in the right direction.
请你能帮助我或引导我朝着正确的方向前进。
All help is appreciated. thanks
感谢所有帮助。谢谢
回答by Ry-
Try this:
试试这个:
window.scroll(0, document.documentElement.scrollHeight)
回答by Dzoki
Something like this?
像这样的东西?
<html>
<head>
<script type="text/javascript">
function moveWin()
{
window.scroll(0,10000);
setTimeout('moveWin();',1000);
}
</script>
</head>
<body onLoad="moveWin();">
<!---- TEXT HERE ---->
</body>
</html>
回答by hotshot309
If you want the page to load at the bottom and not show the scrolling animation, why not add an anchor tag to the very bottom of the page and have your link go straight to it (e.g., http://www.mysite.com/hello#bottom
)? Your anchor tag could look like this: <a name="bottom" id="bottom"></a>
如果您希望页面在底部加载而不显示滚动动画,为什么不在页面的最底部添加一个锚标记并让您的链接直接指向它(例如,http://www.mysite.com/hello#bottom
)?您的锚标记可能如下所示:<a name="bottom" id="bottom"></a>
If you are wondering why I provided both name
and id
in this example, name
is deprecated on <a>
elements as of XHTML 1.0. Until name
is absolutely no longer supported by the (X)HTML standard you are using, it may be safest to use both name
and id
on anchors linking to a part of the same page. This was noted in W3C's XHTML 1 spec.
如果您想知道为什么我在本示例中同时提供name
和id
,从 XHTML 1.0 开始name
不推荐在<a>
元素上使用。在name
您使用的 (X)HTML 标准绝对不再支持之前name
,id
在链接到同一页面一部分的锚点上同时使用和可能是最安全的。这在W3C 的 XHTML 1 规范中有所提及。
回答by mtk
Using jquery you could do this:
使用 jquery 你可以这样做:
$("html, body").animate({ scrollTop: $(document).height() }, "slow");