我在 div 上使用 fadeIn
$(document).scroll(function() {
$('.bottomMenu_alert').fadeIn();
});
用户可以通过单击 div 外部的任意位置来关闭 div
$(document).click(function(event) {
if ( !$(event.target).hasClass('.bottomMenu_alert')) {
$(".bottomMenu_alert").hide();
}
});
但是当用户再次滚动时,div 会重新出现。
如何阻止 div 再次出现?
最佳答案
您可以设置一个简单的标志变量来锁定 div,并且仅在未锁定时淡入。请参阅:
var divLocked = false;
$(document).scroll(function() {
if (!divLocked) { // show only if not locked
$('.bottomMenu_alert').fadeIn();
}
});
$(document).click(function(event) {
if ( !$(event.target).hasClass('.bottomMenu_alert')) {
$(".bottomMenu_alert").hide();
divLocked = true; // lock it after the first click
}
});
关于javascript - 停止在滚动时淡入后出现 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30394078/