Having trouble getting Ariel Flesler's ScrollTo working
I've been trying to implement Ariel Fl开发者_如何学Cesler's ScrollTo plugin, but I can seem to figure out how to initiate it. This is his website:
http://flesler.blogspot.com/
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.
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;
}
}
});
});
精彩评论