2013-04-15 84 views
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> 
+0

你忘了用點 – Musa

+0

你是正確的前綴你的類選擇。但是,修復後它仍然不起作用? – simple

回答

1

試試這個:

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

你要進入下一個DIV(next()),不nextAll()

+0

仍然無法正常工作。我也試過.find – simple

+0

http://jsfiddle.net/HZm7a/1/ - 這是你的代碼。將它更改爲Jozeidon的代碼也是有效的,這表明你的方面有問題。你的jquery是否包含在你的代碼中,並且你的代碼被包裝在$(document).ready()函數中? – Kaloyan

+0

我認爲我的班級元素沒有清除。我改變它尋找下一個H3,它的工作。謝謝。 – simple

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; 
});