自动滚动到页面底部 [英] Scroll Automatically to the Bottom of the Page
问题描述
考虑一下我有一系列问题。当我点击第一个问题时,它会自动将我带到页面底部。
Consider I have a list of questions. When I click on the first question, it should automatically take me to the bottom of the page.
事实上,我知道这可以使用jQuery完成。
For a matter of fact, I do know that this can be done using jQuery.
那么,你能给我一些文件或一些链接,我可以找到这个问题的答案吗?
So, could you provide me with some documentation or some links where I can find answer to this question?
编辑:需要滚动到页面底部的特定HTML 元素
Need to scroll to a particular HTML element at the bottom of the page
推荐答案
jQuery没有必要。我从谷歌搜索获得的大多数顶级结果给了我这样的答案:
jQuery isn't necessary. Most of the top results I got from a Google search gave me this answer:
window.scrollTo(0,document.body.scrollHeight);
如果您有嵌套元素,则文档可能无法滚动。在这种情况下,您需要定位滚动的元素并使用它的滚动高度。
Where you have nested elements, the document might not scroll. In this case, you need to target the element that scrolls and use it's scroll height instead.
window.scrollTo(0,document.querySelector(。scrollingContainer)。scrollHeight);
您可以将其与您问题的 onclick
事件联系起来(即< div onclick = ScrollToBottom()...
)。
You can tie that to the onclick
event of your question (i.e. <div onclick="ScrollToBottom()" ...
).
您可以查看一些其他来源:
Some additional sources you can take a look at:
- http://www.sourcetricks.com/2010/07/ javascript-scroll-to-bottom-of-page.html
- http://www.alecjacobson.com/weblog/?p=753
- http://www.mediacollege.com/internet/javascript/page/scroll.html
- http://www.electrictoolbox.com/jquery-scroll-bottom/
- http://www.sourcetricks.com/2010/07/javascript-scroll-to-bottom-of-page.html
- http://www.alecjacobson.com/weblog/?p=753
- http://www.mediacollege.com/internet/javascript/page/scroll.html
- http://www.electrictoolbox.com/jquery-scroll-bottom/
这篇关于自动滚动到页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!