Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 延迟未在jquery动画队列中正确重新初始化_Javascript_Jquery - Fatal编程技术网

Javascript 延迟未在jquery动画队列中正确重新初始化

Javascript 延迟未在jquery动画队列中正确重新初始化,javascript,jquery,Javascript,Jquery,我的消息框的动画队列有问题 我已经做了一个函数来通知用户应用程序中的错误或信息。 消息将在5秒内显示(延迟),但用户可以通过单击msgbox中的交叉按钮来隐藏消息 我想要的:调用notify()将滑下我的msgbox并在5秒钟后自动淡出()。在5秒延迟之前调用notify()将隐藏()当前msgbox并向下滑动一个新的msgbox,该msgbox将在5秒后再次自动淡出() 我的代码的真正附加内容:如果我在延迟结束前调用“notify()”函数,msgbox将正确隐藏,但新显示的msgbox的延迟

我的消息框的动画队列有问题

我已经做了一个函数来通知用户应用程序中的错误或信息。 消息将在5秒内显示(延迟),但用户可以通过单击msgbox中的交叉按钮来隐藏消息

我想要的:调用notify()将滑下我的msgbox并在5秒钟后自动淡出()。在5秒延迟之前调用notify()将隐藏()当前msgbox并向下滑动一个新的msgbox,该msgbox将在5秒后再次自动淡出()

我的代码的真正附加内容:如果我在延迟结束前调用“notify()”函数,msgbox将正确隐藏,但新显示的msgbox的延迟将短于我的5秒

我尝试使用jQuery函数“.stop(true,true)”重置延迟,但它不起作用。有人知道如何解决我的问题吗

下面是我的片段的一部分: . 要查看问题,请单击按钮,等待2秒钟,然后重新单击按钮。做5次,你会发现msgbox会很快消失

这是我函数的代码

function notify(type, message) {
$('#notificationMessage').stop(true, true).hide();
var classes = 'info warning success error';
$('#notificationMessage').removeClass(classes);
var types = classes.split(' ');
var title = "";

if (type === types[0]) {
    title = "Information";
} else if (type === types[1]) {
    title = "Attention";
} else if (type === types[2]) {
    title = "Succès";
} else if (type === types[3]) {
    title = "Erreur";
} else {
    title = "Information";
    type = types[0];
}
$('#notificationMessage').addClass(type);
$('#notificationMessage h3').empty().append(title);
$('#notificationMessage p').empty().append(message);
$('#notificationMessage').slideDown({ queue: false }).delay(5000).fadeOut(3000); }

$('#btn').on('click',function(){
    notify($('#type').val(),"This is the message to show....");
});

感谢您的帮助

问题是您无法取消
Delay()
您应该改用setTimeout()

从jQuery页面:

.delay()方法最适合在排队的jQuery之间进行延迟 影响。因为它是有限的,例如,它不能提供一种 取消延迟-.delay()不是JavaScript的本机 setTimeout函数,可能更适合某些用途 案例


对于jQuery1.9,您现在可以使用
finish()
方法来清除延迟方法{hooks.stop.call(this,true);}使用的超时

注意:在示例代码中,然后需要在队列中推送slideDown()方法,而不是显式使用
queue:false

$('#notificationMessage').finish().hide();

$('#notificationMessage').finish().hide();