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/