Skip to content

Instantly share code, notes, and snippets.

@Onepo1ntFive
Last active September 4, 2018 08:12
Show Gist options
  • Select an option

  • Save Onepo1ntFive/eb9a77ed5ed852708afdf78f62c4a035 to your computer and use it in GitHub Desktop.

Select an option

Save Onepo1ntFive/eb9a77ed5ed852708afdf78f62c4a035 to your computer and use it in GitHub Desktop.
js. scrolltop
.b-scrolltop {
position: fixed;
z-index: 999;
width: 40px;
height: 40px;
left: 20px;
bottom: -100px;
background-color: #f00;
cursor: pointer;
-webkit-transition: bottom 0.3s ease-out;
transition: bottom 0.3s ease-out;
}
.b-scrolltop--show {
bottom: 20px;
-webkit-transition: bottom 0.3s ease-out;
transition: bottom 0.3s ease-out;
}
var topPos = $(window).height();
var scrollPos = $(window).scrollTop();
function showScrollBtn() {
topPos = $(window).height();
scrollPos = $(window).scrollTop();
if (scrollPos >= topPos ) {
$('.js-scroll-top').addClass('b-scrolltop--show')
} else {
$('.js-scroll-top').removeClass('b-scrolltop--show')
}
}
showScrollBtn();
$(window).on('scroll', function () {
showScrollBtn();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment