Javascript 滚动时,在FadeIn之后停止显示div
我在一个div上使用fadeInJavascript 滚动时,在FadeIn之后停止显示div,javascript,jquery,Javascript,Jquery,我在一个div上使用fadeIn $(document).scroll(function() { $('.bottomMenu_alert').fadeIn(); }); 用户可以通过使用单击div之外的任何位置来关闭div $(document).click(function(event) { if ( !$(event.target).hasClass('.bottomMenu_alert')) { $(".bottomMenu_alert"
$(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
}
});
没问题,我很高兴能帮上忙。:)