Created
November 24, 2014 03:17
-
-
Save chillybin/fded1a432c19338e8960 to your computer and use it in GitHub Desktop.
Back To Top jQuery
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
$(document).ready(function() { | |
var offset = 500; | |
var duration = 1000; | |
$(window).scroll(function() { | |
if ($(this).scrollTop() > offset) { | |
$('.back-to-top').fadeIn(duration); | |
} else { | |
$('.back-to-top').fadeOut(duration); | |
} | |
}); | |
$('.back-to-top').click(function(event) { | |
$('html, body').animate({scrollTop: 0}, duration); | |
return false; | |
event.preventDefault(); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment