【问题标题】:scroll to position jquery offset animation滚动到位置 jquery 偏移动画
【发布时间】:2013-04-23 17:51:23
【问题描述】:

我正在使用以下代码向下滚动到页面底部的联系人部分,该部分运行良好,直到我在页面顶部添加了一个固定导航以向下滚动页面。但不幸的是,导航占据了页面的 100 像素,因此它滚动了 100 像素,超过了我想要的点。我需要将导航高度添加到.offset 以查看页面的正确部分。

如何将导航栏的高度也添加到代码中以将该高度向下滚动到页面下方。

$("document").ready(function() {            

            $('#contact_cntrl').click(function(){

                $('html, body').animate({
                    scrollTop: $(".contact").offset().top
                }, 1000);                  


             });            

【问题讨论】:

    标签: jquery animation jquery-animate offset


    【解决方案1】:

    我相信您想要的是将像素偏移量添加到您的scrollTop。像这样:

    $('html, body').animate({scrollTop: $('.contact').offset().top + 100}, 1000);
    

    【讨论】:

    • 如果 RWD 更改为该高度,我将使用 var 读取导航的高度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多