[Scroll to top] Simple scroll to top button #js
mixin scroll-to-top
a(href="#").page__scroll-to-top.scroll-to-top
svg.scroll-to-top__icon
use(xlink:href="#icon-keyboard_arrow_up")
.scrollback {
width: 56px;
height: 56px;
border-radius: 50%;
transition: transform 0.30s;
transform: scale(0);
&.is-visible {
transform: scale(1);
}
}
$(document).ready(function(){
var toTopBtn = ".scroll-to-top";
var visible = "is-visible"
//Check to see if the window is top if not then display button
$(window).scroll(function(){
if ($(this).scrollTop() > 700) {
$(toTopBtn).addClass(visible);
} else {
$(toTopBtn).removeClass(visible);
}
});
//Click event to scroll to top
$(toTopBtn).click(function(){
$('html, body').animate({scrollTop : 0},2000);
return false;
});
});