jquery - 在 Jquery 中将 Y 位置设置为 px

标签 jquery html css

我在页面左侧设置了一个粘性导航目录以随页面滚动,我使用 Jquery 使其随页面向下滚动。我的位置在距离顶部 150px 的绝对位置,但是当我使用 Jquery 时,它需要导航到达页面顶部而不是跳到顶部:150px 位置但是一旦它达到 150px 我怎样才能激活它远离顶部,因此不再有跳跃。

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

如果您注意到当您向上滚动时,右侧的跳转链接必须先到达页面顶部才能激活固定位置。

我假设我必须更改脚本中的 y >= top 但我不确定如何将其更改为在距顶部 150 像素处激活。

我正在使用的 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');
        }
        });
    });

最佳答案

为什么不直接将 top var 更改为:

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

关于jquery - 在 Jquery 中将 Y 位置设置为 px,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20023846/

相关文章:

css - 使用 "text-decoration-color"不起作用

javascript - jQuery 计算页面滚动厘米数 - 计数器

javascript - 如何在CSS中隐藏一个div

PHP json_encode,数组在 javascript 中未正确显示

html - 创建可折叠的导航栏

html - 针对单个产品 CSS 样式

带下标的 HTML 输入按钮

jquery - 使用 Jquery 是否可以在鼠标悬停时缓慢淡入 div,然后在鼠标移开时快速淡出?

html - 似乎无法通过 CSS 悬停下拉菜单

html - 在网页中心对齐一个水平表单