2012-03-07 18 views
0

私は、ページ内に大量のテキストを含む複数のアコーディオンがあります。一度に開くことができるアコーディオンは1つだけです。私はscrollToプラグインを持っており、アコーディオンがアコーディオンの上部に揃うようにクリックされたときにscrollToをアニメーション化しています。あまりにも多くのテキストがある場合、scrollToはアコーディオンの上部に揃えられません。アニメーションが始まる前にアコーディオンの終了位置を取得する方法はありますか?または単にスクロール位置をアコーディオンに揃えるための解決策ですか?jQuery scrollアコーディオンの終了位置

$(".accordion h3").click(function() { 
    var thisTrigger = $("span", this); 
    var thisIntro = $(this).siblings(".intro"); 
    var thisPane = $(this).siblings(".pane"); 
    var otherIntros = $(this).parents(".parentClass").siblings().find(".intro"); 
    var otherPanes = $(this).parents(".parentClass").siblings().find(".pane"); 
    var otherHeaders = $(otherPanes).siblings(".current"); 
    var otherTriggers = $(otherHeaders).find("span"); 
    if ($(this).hasClass("current")) { 
     $(this).removeClass("current"); 
     $(thisIntro).removeClass("open"); 
     $(thisPane).slideUp("fast"); 
    } else { 
     $(this).addClass("current"); 
     $(thisIntro).addClass("open"); 
     $(thisPane).slideDown("fast"); 
     $(otherIntros).removeClass("open"); 
     $(otherHeaders).removeClass("current"); 
     $('html, body').animate({ scrollTop: $(this).position().top }, 500); 
    } 
}); 
+0

は、あなたは大きなテキストの最後にアンカーリンクを試してみましたか? – ggzone

+0

アコーディオンをクリックすると、テキストの量のために通常よりもはるかにページがスクロールされるので、$(this).position()。topで取り込まれる位置は間違っています。私はちょうどそのアコーデオンの終わりのトップポジションを取得する必要があります。アンカーは機能しません。 – Collin

答えて

1

このリンクは、私を助け: 以下How to set scrollbar to top of section/forget scroll position

は私のコードです:

//initializes accordion 
$("#search").accordion({ 
    header: "h3" 
    , fillSpace: true 
    , active: activeIndex 
    , change: function (event, ui) { 
     var index = $(this).accordion("option", "active"); 
     $("[id$=_hdnAccordionIndex]").val(index);    
     $('.ui-accordion-content').scrollTop(0);    
    } 
}); 
関連する問題