Skip to content

Instantly share code, notes, and snippets.

@koanvl
Last active November 1, 2017 11:35
Show Gist options
  • Save koanvl/ba1172fbfeeef93b56c69a6b009d2e61 to your computer and use it in GitHub Desktop.
Save koanvl/ba1172fbfeeef93b56c69a6b009d2e61 to your computer and use it in GitHub Desktop.
/*button scroll-to-top*/
var amountScrolled = 200;
$(window).scroll(function() {
if ( $(window).scrollTop() > amountScrolled ) {
$('.to-top').fadeIn('slow');
} else {
$('.to-top').fadeOut('slow');
}
});
$('.to-top').click(function() {
$('html, body').animate({
scrollTop: 0
}, 700);
return false;
});
});
//html
<div class="to-top"></div>
//sass
.to-top
width: 50px
height: 50px
box-shadow: 0 2px 4px 0 rgba(0,0,0,.25)
position: fixed
bottom: 111px
right: 43px
background-color: $whiteColor
background-image: url("../img/arrow-top-blue.png")
background-repeat: no-repeat
background-position: center center
cursor: pointer
z-index: 99999
display: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment