开发者

jQuery: slideUp.delay.slideDown - cancel with button?

开发者 https://www.devze.com 2023-03-23 11:17 出处:网络
i don\'t get why this won\'t work. function notificationBoxOutput(type, message) { var noteBox = $(\'.notificationBox\');

i don't get why this won't work.

function notificationBoxOutput(type, message) {
    var noteBox = $('.notificationBox');

    noteBox.sli开发者_如何学运维deDown( function() {
        noteBox.delay(2500).slideUp();
    });
}

function notificationBoxCancel() {
        console.log('successfully fired');
    $('.notificationBox').slideUp();
}

So I call the function notificationBoxOutput to have kind of statusbar on top of the screen that gives some feedback. The bar slidesDown, holds 2,5 secs and then slides up.

The bar itself contains a little closer-icon that fires notificationBoxCancel on click. So the user has the possibility to close the the bar even faster then 2.5 secs. However the closer doesn't work. The console says "successfully fired", but the box doesn't slideUp(). hide() does work! fadeOut() and slideUp() doesn't.

Any idea why?


You should .stop() animations before you slide(them)Up. Try something like this:

function notificationBoxCancel() {
        console.log('successfully fired');
    $('.notificationBox').stop().slideUp();
}


I think it's because animations are queued. Try to call stop before slideUp:

function notificationBoxCancel() {
        console.log('successfully fired');
    $('.notificationBox').stop(true,true).slideUp();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消