Javascript: Scroll to top
.scrollToTop {
bottom: 15px;
right: 12px;
position: fixed;
color: @sun-flower;
display: none;
&:hover {
text-decoration: none;
color: @orange;
}
&:visited {
color: @sun-flower;
}
}
//Check to see if the window is top if not then display button
$(window).scroll(function(){
if ($(this).scrollTop() > 200) {
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
//Click event to scroll to top
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0}, 800);
return false;
});
<a href="#" class="scrollToTop">
<span class="h4">to top</span>
<i class="fa fa-arrow-circle-up fa-3x fa-fw"></i>
</a>