Last active
August 29, 2015 14:15
-
-
Save capitalJT/38f30381effa0818786e to your computer and use it in GitHub Desktop.
Scroll to top gist
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
// calculating some values | |
var header_height = $('.header').outerHeight(), | |
scroll_top_icon = $('#scroll-to-top'), | |
scrollTop = $(window).scrollTop(); | |
// Scroll to top function 1/2 | |
$(function(){ | |
$(window).scroll(function(){ | |
if( scrollTop > header_height ){ | |
scroll_top_icon.fadeIn(); | |
} else { | |
scroll_top_icon.fadeOut(); | |
} | |
}); | |
}); | |
// Scroll to top function 2/2 | |
scroll_top_icon.click(function(){ | |
var body = $("html, body"); | |
body.animate({scrollTop:0}, '500', 'swing'); | |
}); |
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
#scroll-to-top{ | |
position: fixed; | |
z-index: 100; | |
bottom:15px; | |
right:15px; | |
display:none; | |
background-color: rgba(255,255,255,0.8); | |
@include transition(); | |
@include rotate( $val: 180deg ); | |
&:hover{ | |
cursor:pointer; | |
} | |
.icon-ajmn-download{ | |
display:block; | |
padding:0; | |
margin:0; | |
color:$color-accent; | |
font-size:2em; | |
text-align:center; | |
&:before{ | |
float: left; //this is a bit of a hack | |
padding:5px; | |
} | |
} | |
} |
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 id="scroll-to-top"><span class="icon icon-ajmn-download"></span></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment