使用固定的侧栏菜单垂直点击各个部分

时间:2015-02-28 05:29:45

标签: jquery html

我有一个单页的网站,分为几个部分。我有两个箭头,一个向上,一个向下,点击时应滚动到下一个或上一个部分。箭头是固定元素。

任何关于它为什么不起作用的指示都将不胜感激, 提前谢谢!

JQUERY

<script>
jQuery.fn.extend({
scrollTo : function(speed, easing) {
return this.each(function() {
  var targetOffset = $(this).offset().top;
  $('html,body').animate({scrollTop: targetOffset}, speed, easing);
});
}
});

$('.next-section').click(function(e){
e.preventDefault();
var $this = $(this),
    $next = $this.parent().next();

$next.scrollTo(400, 'linear');
});

$('.prev-section').click(function(e){
e.preventDefault();
var $this = $(this),
    $prev = $this.parent().prev();

$prev.scrollTo(400, 'linear');
});
</script>

HTML

<div id="arrowmenu">
<a href="#" class="prev-section"><img src="../images/up.png"></a><br>
<a href="#" class="next-section"><img src="../images/down.png"></a><br>
</div>

和我的部分分开如此:

<div class="section" id="section2">
Content...
</div>

0 个答案:

没有答案