Last active
September 4, 2018 08:12
-
-
Save Onepo1ntFive/eb9a77ed5ed852708afdf78f62c4a035 to your computer and use it in GitHub Desktop.
js. scrolltop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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