Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transition End Fallback for ie9

I'm using the following code with jquery to trigger events on transitionend and avoid multiple callback/support multiple browsers:

function whichTransitionEvent(){
    var t;
    var el = document.createElement('fakeelement');
    var transitions = {
      'transition':'transitionend',
      'OTransition':'oTransitionEnd',
      'MozTransition':'transitionend',
      'WebkitTransition':'webkitTransitionEnd'
    }

    for(t in transitions){
        if( el.style[t] !== undefined ){
            return transitions[t];
        }
    }
}

(code found here: http://davidwalsh.name/css-animation-callback)

However, it seems that ie9 doesn't support transitionend regardless of the prefix/syntax. How would I set up a fallback for ie9 when i'm using it in a scenario like the following (to remove a loading screen from the DOM after animation is complete)?

$('#loading').one(transitionEvent, function(event) {
      $('#loading').remove();
});

I've seen several answers about how to prevent multiple callbacks using a similar function to the one at the top of this post, but am just not understanding how to create a fallback. Thanks for your help!

like image 706
christopher Avatar asked Jul 01 '15 21:07

christopher


1 Answers

var transitionEvent = whichTransitionEvent();

// bind your event
$('#loading').one(transitionEvent, function(event) {
  $('#loading').remove();
});

// if event not supported e.g. IE <= 9
if (! transitionEvent) {
  $('#loading').trigger(transitionEvent);
}

The function returns a falsy value (undefined), if the event is not supported.

like image 186
NehrDani Avatar answered Nov 15 '22 10:11

NehrDani