Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery slideDown callback if complete or fail.. 'always' option

Tags:

jquery

Silly question but i can't seem to figure it out.

In the jquery documents it shows an option in the slideUp() function which is "always". which will call a function once the animation completes or fails How do i implement this?

http://api.jquery.com/slideUp/

$(".toHide").slideUp(function(){
   alert();
})

basically want that alert to be called no matter what after the animation.. currently only calls if it completes not fail.

animation fails if the class doesnt yet exist

like image 863
Dustin Silk Avatar asked Jul 09 '13 15:07

Dustin Silk


2 Answers

All animations can generate promise objects which have an always method.

$(".toHide").slideUp().promise().always(function(){
    alert("foobar");
});

however, animations can't "fail", so it's irrelevant anyway.

like image 93
Kevin B Avatar answered Oct 03 '22 12:10

Kevin B


Options are typically in the format of {option: optionVal, option2: option2Val}

$('.toHide').slideUp({ 
  always: function(Promise animation, Boolean jumpedToEnd){}
});
like image 44
damian Avatar answered Oct 03 '22 11:10

damian