jQuery scrollTo手风琴结束位置 [英] jQuery scrollTo accordion end position

查看:92
本文介绍了jQuery scrollTo手风琴结束位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面上有多个手风琴,每个手风琴中都有大量文本.一次只能打开一个手风琴.我有scrollTo插件,单击手风琴以使其与手风琴的顶部对齐时,我正在为scrollTo设置动画.如果文本太多,scrollTo不会与手风琴顶部对齐.有没有办法在动画开始之前获得手风琴的结束位置?或者只是将滚动位置与手风琴对齐的分辨率?

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. If I have too much text, the scrollTo doesn't align to the accordion top. 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

下面是我的代码:

//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);            
    }
});

这篇关于jQuery scrollTo手风琴结束位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆