Well, let’s come to the development requirements. When the webpage has a lot of content, users need to have a button to quickly return to the top, instead of rolling the wheel themselves~
I originally thought it would be difficult to say, because the above requires all to be used. js to implement, which page is referenced and which page is displayed.
So, I tried to write it down, eh, I didn’t find it, it’s pretty easy to say~~
I’ll fart as soon as I can, go directly to the code, there’s a lot of farts It becomes shit~~ Well, sin, Amitabha, Amen~~
//Back to top js
$(function(){
var $btn_top = $('');
$btn_top.css({
'display':'none',
'width':'40px',
'height':'40px',
'position':'fixed',
'right':'20px',
'bottom' :'100px',
'z-index':'999'
});
$("body").append($btn_top);
$("body").on ("click","#scrollTopBtn",function(){
$("html,body").animate({scrollTop: 0},"slow");
});
var $ btn = $("#scrollTopBtn");
if($(window).scrollTop() > 100){
$btn.fadeIn(600);
}
$(window) .scroll(function(){
if($(window).scrollTop() > 100){
$btn.fadeIn(600);
}else{
$btn.fadeOut( 600);
}
});
});