Last active
May 27, 2018 19:00
-
-
Save bbrochier/6668684 to your computer and use it in GitHub Desktop.
Go Top Sticky button
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
/* Go Top */ | |
.go-top { | |
position: fixed; | |
bottom: 2em; | |
right: 2em; | |
text-decoration: none; | |
color: white; | |
background-color: #f6f6f6; | |
background-color: rgba(0, 0, 0, 0.3); | |
font-size: 12px; | |
padding: 18px; | |
border-radius: 3px; | |
display: none; | |
-webkit-transition: all 0.3s ease-out; | |
-moz-transition: all 0.3s ease-out; | |
-o-transition: all 0.3s ease-out; | |
transition: all 0.3s ease-out; | |
} | |
.go-top:hover { | |
background-color: rgba(0, 0, 0, 0.6); | |
} | |
.go-top i { | |
height: 0; | |
width: 0; | |
position: absolute; | |
top: 9px; | |
left: 8px; | |
border-bottom: 17px solid white; | |
border-left: 10px solid transparent; | |
border-right: 10px solid transparent; | |
} |
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
<a href="#" class="go-top"><i></i></a> |
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
// Source: http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/quick-tip-implement-a-sticky-back-to-top-button/ | |
/* Stiky GOTO Top | |
======================================================================= */ | |
// Show or hide the sticky footer button | |
$(window).scroll(function() { | |
if ($(this).scrollTop() > 200) { | |
$('.go-top').fadeIn(600); | |
} else { | |
$('.go-top').fadeOut(600); | |
} | |
}); | |
// Animate the scroll to top | |
$('.go-top').click(function(event) { | |
event.preventDefault(); | |
$('html, body').animate({scrollTop: 0}, 300); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment