滚动到最后一个div的顶部后转到第一个div

时间:2014-03-06 07:33:05

标签: javascript jquery html5 css3

我有滚动问题。 点击<a href="#" id="display" class="display">next</a>标记时, 页面滚动到下一个div。当滚动到上一个div的顶部,然后点击&#34;下一个&#34;时,它必须转到第一个div的顶部,但它不会。

demo

2 个答案:

答案 0 :(得分:1)

修改了你的代码:

  if (t === 'next' ) {
    if($('.current').next('.section').length==0)
    var $next = $('#one');
    else
    var $next = $('.current').next('.section');
  }

<强> Working Demo

答案 1 :(得分:0)

if (t === 'next') {

    var $next = $('.current').next('.section');

    //so no more next
    if (!$next.length)
        $next = $('div.section').first();

http://jsfiddle.net/aVJBY/270/

相关问题