Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Jquery中将Y位置设置为px_Jquery_Html_Css - Fatal编程技术网

在Jquery中将Y位置设置为px

在Jquery中将Y位置设置为px,jquery,html,css,Jquery,Html,Css,我在页面左侧设置了一个粘性的nav目录,以便与页面一起滚动,我使用Jquery使其与页面一起向下滚动。我有绝对位置150px的位置从顶部,但当我使用Jquery时,它要求导航点击页面顶部,然后跳转到顶部:150px位置,但我如何让它在到达150px的位置后激活,这样就不再有跳转了 您可以在 如果您注意到,当您向上滚动时,右侧的跳转链接必须在激活固定位置之前到达页面顶部 我假设我必须更改脚本中的y>=top,但我不确定如何将其更改为从顶部以150px的速度激活 我使用的Jquery是 $(docu

我在页面左侧设置了一个粘性的nav目录,以便与页面一起滚动,我使用Jquery使其与页面一起向下滚动。我有绝对位置150px的位置从顶部,但当我使用Jquery时,它要求导航点击页面顶部,然后跳转到顶部:150px位置,但我如何让它在到达150px的位置后激活,这样就不再有跳转了

您可以在

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

我假设我必须更改脚本中的y>=top,但我不确定如何将其更改为从顶部以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 top = $('#jump-list').offset().top - 100

谢谢,它仍然有一点点的跳跃,这是固定的还是没有?