function backToTop() {
var scrollPos = 0;
var element = $('#back-to-top');
$(window).scroll(function() {
var scrollCur = $(window).scrollTop();
if(scrollCur > scrollPos){
// scroll down
if(scrollCur > 500){
element.addClass('active');
}
else {
element.removeClass('active');
}
}
else {
// scroll up
element.removeClass('active');
}
scrollPos = scrollCur;
});
element.on('click',function(){
$('html, body').animate({scrollTop: '0px'}, 800);
})
}
Make back-to-top button smooth. Button was show when scroll down.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.