Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

javascript - 自动滚动到页面底部(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.(当我点击第一个问题时,它会自动将我带到页面底部。)

For a matter of fact, I do know that this can be done using jQuery.(事实上,我知道这可以使用jQuery完成。)

So, could you provide me with some documentation or some links where I can find answer to this question?(那么,你能给我一些文件或一些链接,我可以找到这个问题的答案吗?)

EDIT: Need to scroll to a particular HTML element at the bottom of the page(编辑:需要滚动到页面底部的特定HTML 元素)

  ask by jat translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

jQuery isn't necessary.(jQuery没有必要。)

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);

You can tie that to the onclick event of your question (ie <div onclick="ScrollToBottom()" ... ).(您可以将其与问题的onclick事件联系起来(即<div onclick="ScrollToBottom()" ... )。)

Some additional sources you can take a look at:(您可以查看一些其他来源:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...