Last active
December 23, 2015 16:09
-
-
Save oliverbenns/6660703 to your computer and use it in GitHub Desktop.
Simple 'To Top' button script if browser goes below the fold.
This file contains 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
$(window).scroll(function() { | |
var window_height = $(window).height(); | |
if ( $(window).scrollTop() > window_height ) { | |
$('.to-top').addClass('show'); | |
} else { | |
$('.to-top').removeClass('show'); | |
} | |
}); |
This file contains 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
<div class="to-top">To Top</div> |
This file contains 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
.to-top { | |
display: none; | |
position: fixed; | |
/* style/position where you like */ | |
bottom: 40px; | |
left: 40px; | |
} | |
.show { | |
display: block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment