2014-12-31 223 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