【问题标题】:scrollIntoView() with fixed header带有固定标题的 scrollIntoView()
【发布时间】:2018-09-07 13:00:37
【问题描述】:

这可能是一个简单的问题,但我需要一些帮助。

我有这个代码:

var lastitem='';
(function($) {

var allPanels = $('.accordion> dd').hide();

$('.accordion > dt > a').click(function() {
    allPanels.slideUp();
    if ($(this).text() != lastitem) {
        $(this).parent().next().slideDown();
        lastitem = $(this).text();
        $(this).get(0).scrollIntoView({
            behavior: "smooth", // or "auto" or "instant"
            block: "start" // or "end"
        });
    } else {
        lastitem = '';
    };
    return false;
  });

})(jQuery);

我有一个固定的标题,所以当我点击手风琴时,它会滚动到视口中,问题是我的固定标题。我需要从顶部滚动到视口 + 100px。

类似:

$(this).get(0).scrollIntoView({
    behavior: "smooth", // or "auto" or "instant"
    block: "start + 100px" // or "end"
});

就是这样,有什么建议吗?谢谢!!

【问题讨论】:

标签: javascript jquery scroll scrollview


【解决方案1】:

根据我从 scrollIntoView 的规范中读到的内容,您不能在块上偏移。

【讨论】:

    猜你喜欢
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多