Javascript jQuery:具有通知功能的超时/延迟?

Javascript jQuery:具有通知功能的超时/延迟?,javascript,jquery,debugging,timeout,delay,Javascript,Jquery,Debugging,Timeout,Delay,我编写了以下简单函数,该函数接受两个参数,这些参数主要来自服务器返回的json函数 var timing = 10000; function notificationOutput(type, message) { console.log('output now!'); var note = $('.notification'); note.css('display', 'none'); if ( type == "success" ) { note.remove

我编写了以下简单函数,该函数接受两个参数,这些参数主要来自服务器返回的json函数

var timing = 10000;

function notificationOutput(type, message) {
    console.log('output now!');
    var note = $('.notification');
    note.css('display', 'none');
    if ( type == "success" ) { note.removeClass('warning').addClass('success'); }
    if ( type == "warning" ) { note.removeClass('success').addClass('warning'); }
    note.find('.message').html(message);
    note.slideDown( function() {
        note.delay(timing).slideUp();
    });
}
它所做的只是从我的页面顶部滑下一个条,发出一条消息(成功或警告)。
定时变量用于通知栏保持10秒。因此,当该函数被触发时,我希望该条
slideDown()
,保持该位置10秒,然后再
slideUp()

但是现在当函数被触发时,会出现一个奇怪的超时,直到通知栏出现。这意味着,当函数启动时,我现在在那里的
console.log()
输出会立即记录在我的JS控制台中,但slideDown()的显示时间会延长几秒钟!为什么呢

我希望
slideDown()。为什么会发生延迟


谢谢你的帮助

那里没有什么明显的东西。我会尝试裁剪代码,直到它像预期的那样向下滑动。移除回调、移除html集、移除成功/警告类设置器、在输出到控制台之前选择note元素、用即时显示替换幻灯片等


还可以尝试先调用便笺上的
.stop(true,true)
note.stop(true,true).slideDown()。这是为了防止它正忙于其他动画,而向下滑动正在排队。

试试这个

note.slideDown().delay(timing).slideUp();

我认为问题可能出在slideDown所使用的
easing
函数中,默认情况下,slideDown是
swing
(对数)。尝试使用线性,或者尝试使用更快的向下滑动时间

note.slideDown(400, 'linear').delay(timing).slideUp(400, 'linear');

您没有将
duration
的值传递给
slideDown
。尝试:

note.slideDown(1000, function() {
  note.delay(timing).slideUp();
});

旁注:
note.slideDown().delay(计时).slideUp()也可以。这里不需要使用完成的回调。奇怪的是,
note.stop(true,true)。slideDown()完成了工作。当我将它设置为just
show()
时,它确实可以正常工作。不知道排队的人是从哪里来的。有什么想法吗?没有。可能是意外地附加了其他动画。如果你真的想知道,那么我会尽可能地删除/禁用所有其他内容,直到它按预期工作。嘿,另一个问题。我对
delay()
函数也有同样的问题…如果
定时
变量设置为10000,则通知仅停留3秒钟左右。可能还有其他干扰?没有测试用例很难说。