jQuery.fn.extend({
scrollTo : function(speed, easing) {
return this.each(function() {
var targetOffset = $(this).offset().top;
$('html,body').animate({scrollTop: targetOffset}, speed, easing);
});
}
});
// Scroll to "about" section
$('#about').scrollTo('fast', 'linear');
更新 - 从一节跳转到节用一个简单的事件处理程序:
JQuery的:
$('.next-section').click(function(){
var $this = $(this),
$next = $this.parent().next();
$next.scrollTo($next.offset().top, 500, 'linear');
});
$('.prev-section').click(function(){
var $this = $(this),
$prev = $this.parent().prev();
$prev.scrollTo($prev.offset().top, 500, 'linear');
});
HTML:
<section id="about">
<a href="#" class="prev-section">Previous Section</a>
<a href="#" class="next-section">Next Section</a>
<div class="section-content">
Foobar
</div>
</section>
这里有一个演示:http://jsfiddle.net/AlienWebguy/Xdg2k/
你的问题是什么? – Birey
我认为这很明显:“但我想要求一些不同的选择。”正如我所说的,我使用的是一个名为“Smooth Scroll”的选项,但它有点不一致。 – dcolumbus