我在页面左侧设置了一个粘性导航目录以随页面滚动,我使用 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/