Last active
December 12, 2015 09:19
-
-
Save omniosi/4751038 to your computer and use it in GitHub Desktop.
animated scrolling to links in 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
The function for the horizontal scrolling effect is the following: | |
$(function() { | |
$('ul.nav a').bind('click',function(event){ | |
var $anchor = $(this); | |
/* | |
if you want to use one of the easing effects: | |
$('html, body').stop().animate({ | |
scrollLeft: $($anchor.attr('href')).offset().left | |
}, 1500,'easeInOutExpo'); | |
*/ | |
$('html, body').stop().animate({ | |
scrollLeft: $($anchor.attr('href')).offset().left | |
}, 1000); | |
event.preventDefault(); | |
}); | |
}); | |
And the function for the vertical scrolling effect is the following: | |
$(function() { | |
$('ul.nav a').bind('click',function(event){ | |
var $anchor = $(this); | |
$('html, body').stop().animate({ | |
scrollTop: $($anchor.attr('href')).offset().top | |
}, 1500,'easeInOutExpo'); | |
/* | |
if you don't want to use the easing effects: | |
$('html, body').stop().animate({ | |
scrollTop: $($anchor.attr('href')).offset().top | |
}, 1000); | |
*/ | |
event.preventDefault(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment