【发布时间】:2021-04-23 22:49:28
【问题描述】:
我想在滚动后显示一个 DIV,例如向下 800 像素。 为此,我使用great snippet from here:
$(document).scroll(function() {
var y = $(this).scrollTop();
if (y > 800) {
$('.bottomMenu').fadeIn();
} else {
$('.bottomMenu').fadeOut();
}
});
效果很好。但现在我想添加另一个步骤。
如果我滚动到站点的.footer,我想再次隐藏 DIV,直到我离开页脚。
我想我可以从上面的答案中更改另一个 sn-p:
$('.footer').each(function () {
var y = $(document).scrollTop();
var t = $(this).parent().offset().top;
if (y > t) {
$('.bottomMenu').fadeIn();
} else {
$('.bottomMenu').fadeOut();
}
});
不幸的是,我无法弄清楚。
【问题讨论】:
-
您的第二个 sn-p 只会在页面加载时被调用。这是你的意图吗?
-
不,如果我输入
.footer并在离开它之后应该调用它:-/ -
我会尝试使用交叉点观察器。
标签: javascript html jquery css scroll