Skip to content

Instantly share code, notes, and snippets.

@zdimaz
Last active October 25, 2021 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdimaz/fefdb244603405749eec48a9d5059028 to your computer and use it in GitHub Desktop.
Save zdimaz/fefdb244603405749eec48a9d5059028 to your computer and use it in GitHub Desktop.
btn to top scroll
js
$(window).on("scroll", function(){
if ($(this).scrollTop() > 100) {
$('.btn_scrollup').fadeIn();
} else {
$('.btn_scrollup').fadeOut();
}
});
$('.btn_scrollup').on('click', function(){
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
HTML
<a href="#" class="btn_scrollup">Scroll</a>
CSS
.btn_scrollup{
width:40px;
height:40px;
opacity:0.3;
position:fixed;
bottom:50px;
right:80px;
display:none;
text-indent:-9999px;
background-color: red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment