Reputation: 529
I've been trying to implement Ariel Flesler's ScrollTo plugin, but I can seem to figure out how to initiate it. This is his website:
What I would like to do is have a static navigation, and when the user clicks a nav link, the content scrolls within a particular div. I have a pretty good understanding of jQuery, and it seems like this plugin should be really easy to use, but the documentation kinda sucks for demonstrating how to actually use it.
Upvotes: 1
Views: 436
Reputation: 5905
Peter is right, you can do this:
$(document).ready(function(){
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target
|| $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body')
.animate({scrollTop: targetOffset}, 1000);
return false;
}
}
});
});
Upvotes: 1