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