Home > Web Front-end > JS Tutorial > js hide and show back to top button and window.onscroll event application_javascript skills

js hide and show back to top button and window.onscroll event application_javascript skills

WBOY
Release: 2016-05-16 17:42:47
Original
1092 people have browsed it

Now most websites will add this function: when the scroll bar scrolls to the bottom of the page, a "back to top" button or link will be displayed in the lower right corner of the page. After clicking the button, the page will jump to the top, or A suitable location for viewing the content.

So, how to control the display or hiding of the "Back to Top" button? In fact, we only need to implement the window.onscroll event. The code is as follows:

Copy the code The code is as follows:

window.onscroll = function () {
if (document.documentElement.scrollTop document.body.scrollTop > 100) {
document.getElementById("scrollto").style.display = "block" ;
}
else {
document.getElementById("scrollto").style.display = "none";
}
}

scrollto is the page Container (div tag) on ​​"back to top"
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template