在jquery中设置延迟淡出或点击后立即淡出
我正在尝试纠正通知弹出窗口的脚本。我不希望弹出窗口在 X 秒后淡出或在用户单击消息时淡出。我可以让这两种效果单独工作,但是当我尝试将它们组合起来时,淡出效果有效。到目前为止,这是我的代码:
function notify(data, type) {
switch(type) {
case "success":
$('#notify').html(data)
.removeAttr("style")
.addClass('notifySuccess')
.click(function() {
$("#notify").fadeOut();
})
.delay(5000).fadeOut();
break;
case "error":
$('#notify').html(data)
.removeAttr("style")
.addClass('notifyFailure')
.click(function() {
$("#notify").fadeOut();
})
.delay(5000).fadeOut();
break;
}
}
I am trying to right a script for a notification popup. I wan't the popup to fade out after X seconds or fadeout when the user clicks on the message. I can get both effects to work individually but when I try to combine them fadeOut works. This is my code so far:
function notify(data, type) {
switch(type) {
case "success":
$('#notify').html(data)
.removeAttr("style")
.addClass('notifySuccess')
.click(function() {
$("#notify").fadeOut();
})
.delay(5000).fadeOut();
break;
case "error":
$('#notify').html(data)
.removeAttr("style")
.addClass('notifyFailure')
.click(function() {
$("#notify").fadeOut();
})
.delay(5000).fadeOut();
break;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试放置 .stop();
try putting .stop();
您需要一个
.stop()
来清除延迟 :另外,如果类型只有
success
和error
,则可以大大缩短它,如下所示You need a
.stop()
in there to clear the delay out of the queue, like this:Also, if you only have
success
anderror
for types, you can shorten this down a great deal, like this: