滚动到下一堂课

时间:2013-04-15 21:45:09

标签: jquery

如何将此滚动条滚动到下一个类?

var $root = $('html, body');
$('a.scroll-to-next-nav').click(function(){
    $root.animate({
        scrollTop: $( $(this).closest('.header-icons').nextAll('.header-icons') ).offset().top
    }, 500);
    return false;
});

<div class="header-icons"><a href="#" class="scroll-to-next-nav" title="Go to next section">Go to next section</a></div>


<div class="header-icons"><a href="#" class="scroll-to-next-nav" title="Go to next section">Go to next section</a></div>
<div class="header-icons"><a href="#" class="scroll-to-next-nav" title="Go to next section">Go to next section</a></div>

2 个答案:

答案 0 :(得分:1)

试试这个:

scrollTop: $(this).closest('.header-icons').next('.header-icons').offset().top

您想转到下一个div(next()),而不是nextAll()

答案 1 :(得分:0)

希望这有帮助! :)

var $root = $('html, body');
var i=$('a.next').length, v=1;
$('a.next').click(function(){
    var to = v<i ? $(this).closest('.page').next('.page').offset().top : 0;
    $root.animate({
        scrollTop: to
    }, 500);
    if(v<i) {v++;} else {v=1;}
    return false;
});