在 Jquery 中将 Y 位置设置为 px



我正在页面左侧设置一个粘性导航目录以随页面滚动,并且我正在使用Jquery让它随页面向下滚动。我的位置在距离顶部 150px 的绝对位置,但是当我使用 Jquery 时,它需要导航到达页面顶部而不是跳转到顶部:150px 位置,但是一旦它到达距离顶部 150px 的位置,我如何让它激活,所以不再有跳跃。

您可以在 http://stormable.com/heroes/malfurion/查看此内容

如果您注意到向上滚动时右侧的跳转链接必须在激活固定位置之前点击页面顶部。

假设我必须更改脚本中的 y>= 顶部,但我不确定如何更改它以从顶部激活 150px。

我正在使用的 Jquery 是

$(document).ready(function () {  
    var top = $('#jump-list').offset().top - parseFloat($('#jump-list').css('marginTop').replace(/auto/, 0));
    $(window).scroll(function (event) {
        // what the y position of the scroll is
        var y = $(this).scrollTop();
        // whether that's below the form
        if (y >= top) {
          // if so, ad the fixed class
          $('#jump-list').addClass('fixed');
        } else {
          // otherwise remove it
          $('#jump-list').removeClass('fixed');
        }
        });
    });

你为什么不把顶部的var更改为:

 var top = $('#jump-list').offset().top - 100

最新更新