Share with you today on the page often appear in return to the top effect
Can omit a lot of code compared to the native Javascript,jquery implementation.
The next step is to post the code directly:
$ (function () {
$ (window). Scroll (function () {//scroll--browser scroll bar scrolling triggers
var wheight=$ (window). Height (); Gets the height of the browser visual window
var wtop=$ (window). scrolltop ()///Get the scroll bar distance to the top
if (wtop>=wheight)///When the scroll bar is more than one screen from the top height
$ ("#btn"). Show ()///Return Top button display
}
else{
$ ("#btn"). Hide ();//back to top button hide
}
);
$ ("#btn"). Click (function () {
$ ("Html,body"). Animate ({scrolltop:0},500);//page 500 milliseconds to return top
});
OK, is not very simple, jquery directly provides us with the Animate method can quickly achieve return to the top of the animation effect.
The above is the entire content of this article, I hope to help you, but also hope that a lot of support cloud Habitat community!