Created
July 15, 2014 21:04
-
-
Save anilex/29c3467594af50d62fcb to your computer and use it in GitHub Desktop.
Scroll Top
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
// http://codyhouse.co/demo/back-to-top/ | |
jQuery(document).ready(function($) { | |
// browser window scroll (in pixels) after which the "back to top" link is shown | |
var offset = 300, | |
//browser window scroll (in pixels) after which the "back to top" link opacity is reduced | |
offset_opacity = 1200, | |
//duration of the top scrolling animation (in ms) | |
scroll_top_duration = 700, | |
//grab the "back to top" link | |
$back_to_top = $('.cd-top'); | |
//hide or show the "back to top" link | |
$(window).scroll(function() { | |
($(this).scrollTop() > offset) ? $back_to_top.addClass('cd-is-visible') : $back_to_top.removeClass('cd-is-visible cd-fade-out'); | |
if ($(this).scrollTop() > offset_opacity) { | |
$back_to_top.addClass('cd-fade-out'); | |
} | |
}); | |
//smooth scroll to top | |
$back_to_top.on('click', function(event) { | |
event.preventDefault(); | |
$('body,html').animate({ | |
scrollTop: 0, | |
}, scroll_top_duration); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment