0

我如何使这个滚动到下一堂课?

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>
4

2 回答 2

1

试试这个:

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

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

于 2013-04-15T21:53:15.027 回答
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;
});
于 2013-04-15T23:45:48.057 回答