首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ScrollTop问题

ScrollTop问题
EN

Stack Overflow用户
提问于 2014-05-21 16:55:17
回答 1查看 76关注 0票数 0

我有一个手风琴功能,不调整窗口的顶部打开元素时,它被点击。查看移动或小屏幕大小,以了解我在说什么:http://startyourlife.com/biz-training/

下面是一个可以工作的示例:http://tympanus.net/Tutorials/FlexibleSlideToTopAccordion/

如果单击它,您将看到它滚动到该元素的顶部。下面是我目前拥有的javascript:

代码语言:javascript
复制
if (section_title.length) {
    section_title.click(function () {
        if ((!section.hasClass('active')) && (!running)) {
            running = true;
            var currentHeight, newHeight;
            items.each(function () {
                if ($(this).hasClass('active')) {
                    $(this).removeClass('active');
                }
            });
            if (item.length) {
                item.addClass('active');
            }

            sections.each(function () {
                if ($(this).hasClass('active')) {
                    currentHeight = $(this).find('.w-timeline-section-content').height();
                    $(this).find('.w-timeline-section-content').slideUp();
                }
            });

            newHeight = section_content.height();

            if (activeIndex < index) {

                $('html').animate({
                    scrollTop: $('html').scrollTop() - currentHeight
                });
            }

            section_content.slideDown(null, function () {
                sections.each(function () {
                    if ($(this).hasClass('active')) {
                        $(this).removeClass('active');
                    }
                });
                section.addClass('active');
                activeIndex = index;
                running = false;
            });

        }
    });
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-22 15:11:21

修正后,在最后一行“the = false”后面添加以下内容

代码语言:javascript
复制
var target = $(section);
    if (target.length) {
        $('html,body').animate({
            scrollTop: target.offset().top
        }, 1000);
        return false;
     }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23789459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档