Skip to content

Instantly share code, notes, and snippets.

@bbrochier
Last active May 27, 2018 19:00
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bbrochier/6668684 to your computer and use it in GitHub Desktop.
Save bbrochier/6668684 to your computer and use it in GitHub Desktop.
Go Top Sticky button
/* 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;
}
<a href="#" class="go-top"><i></i></a>
// 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