Reputation: 2397
How do I make this scroll to the next class?
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>
Upvotes: 0
Views: 1155
Reputation: 3348
hope this helps! :)
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;
});
Upvotes: 0
Reputation: 33
Try with this:
scrollTop: $(this).closest('.header-icons').next('.header-icons').offset().top
You want to go to the next div (next()
), not nextAll()
Upvotes: 1