Skip to content

Instantly share code, notes, and snippets.

@capitalJT
Last active August 29, 2015 14:15
Show Gist options
  • Save capitalJT/38f30381effa0818786e to your computer and use it in GitHub Desktop.
Save capitalJT/38f30381effa0818786e to your computer and use it in GitHub Desktop.
Scroll to top gist
// 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');
});
#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;
}
}
}
<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