Last active
August 10, 2016 19:55
-
-
Save marcelo-ribeiro/967c17035fdc2643d3d5 to your computer and use it in GitHub Desktop.
Smooth Scroll to top and to target
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
// --------------------------------------------------------- | |
// Back to Top | |
// --------------------------------------------------------- | |
$(window).scroll(function () { | |
if ($(this).scrollTop() > 100) { | |
$('#back-top').fadeIn(); | |
} else { | |
$('#back-top').fadeOut(); | |
} | |
}); | |
$('#back-top a').click(function () { | |
$('body').animate({ | |
scrollTop: 0 | |
}, 800); | |
return false; | |
}); |
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
// Listen all anchors click | |
$('[data-href]').click(function(){ | |
var target = $(this).attr('data-href'); | |
$('body').animate({ | |
scrollTop: $(target).offset().top | |
}, 800); | |
return false; // Prevent anchor to add hash on url | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment