Skip to content

Instantly share code, notes, and snippets.

@AntonLitvin
Last active December 29, 2017 10:14
Show Gist options
  • Save AntonLitvin/9dc9d119c622707bc573aaa76e1086a6 to your computer and use it in GitHub Desktop.
Save AntonLitvin/9dc9d119c622707bc573aaa76e1086a6 to your computer and use it in GitHub Desktop.
<div class="to-top"><i class="fa fa-angle-double-up"></i></div>
.to-top{
position: fixed;
right: 25px;
bottom: 25px;
width: 50px;
height: 50px;
border-radius: 50%;
text-align: center;
cursor: pointer;
z-index: 100;
opacity: .7;
background-color: teal;
color: #fff;
transition: all 0.25s;
display: none;
.fa {
font-size: 32px;
line-height: 50px;
}
&:hover {
opacity: 1;
}
}
/*To top button*/
$('.to-top').on('click', function() {
$('body, html').animate({ scrollTop:0 },800);
return false;
});
$(window).scroll(function() {
if($(this).scrollTop() > $(window).height()) {
$('.to-top').fadeIn();
} else {
$('.to-top').fadeOut();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment