[英]jQuery scrollTo accordion end position
I have multiple accordions on a page which have large amounts of text inside each. 我的页面上有多个手风琴,每个手风琴内都有大量文本。 Only one accordion can be opened at once. 一次只能打开一个手风琴。 I have scrollTo plugin and I'm animating the scrollTo when an accordion is clicked to align with the top of the accordion. 我有scrollTo插件,单击手风琴以使其与手风琴的顶部对齐时,我正在为scrollTo设置动画。 If I have too much text, the scrollTo doesn't align to the accordion top. 如果文本太多,scrollTo不会与手风琴顶部对齐。 Is there a way to get the ending position of the accordion before the animation starts? 有没有办法在动画开始之前获得手风琴的结束位置? Or simply a resolution to aligning the scroll position to the accordion? 或者只是将滚动位置与手风琴对齐的分辨率?
$(".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);
}
});
This link helped me: How to set scrollbar to top of section / forget scroll position 此链接对我有帮助: 如何将滚动条设置为部分顶部/忘记滚动位置
Below is my code: 下面是我的代码:
//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);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.