2014-12-31 221 views
1

我想滾動到一個動態的ID。我正在使用以下jqueryJQuery滾動到動態ID

$('.toggle-explanation').click(function() { 
    var divID = '#explanation-' + $(this).attr('rel'); 
    //var divID = '#explanation-' + $(this).attr('id'); 
    $('html, body').animate({scrollTop: $(divID).offset().top}, {queue: false, duration: 900}); 
    $($(this).attr('rel')).slideToggle(900); 
    }); 

    ----- 

<a class="toggle-explanation" rel="#explanation-<?php the_ID(); ?>" href="javascript:void(0);">Explanation &gt;</a> 

我不知道爲什麼它不起作用。

+0

在DIVID取出explanation-一部分,現在你」重新得到解釋 - 解釋phpid – thepieterdc

回答

1

這不是工作,因爲您創建的VAR DIVID看起來認爲: 「#explanation-#explanation-」

試試這個方法:

var divID = $(this).attr('rel'); 
+0

thanx,那沒有工作。它打開解釋,但只滾動到位置與我第二次點擊鏈接關閉。 – russ