Skip to content

$.fn.animationComplete doesn't release callback when $.support.cssTransitions=true #5156

Closed
nonplus opened this Issue Oct 11, 2012 · 0 comments

1 participant

@nonplus
nonplus commented Oct 11, 2012

In v1.2.0 and earlier, $.fn.animationComplete(callback) leaks the supplied callback.

When $.support.cssTransitions is true in $.fn.animationComplete(), the function attaches the callback to both the webkitAnimationEnd and the animationend events.

However, only one of these will fire depending on the browser. For example, on WebkKit, the webkitAnimationEnd will fire but the callback will be retained on behalf of the animationend event which never fires. This leads to memory leaks.

The fix is to attach to a browser-specific event:

//animation complete callback
var animationEndEvent = "WebKitTransitionEvent" in window ? "webkitAnimationEnd" : "animationend";
$.fn.animationComplete = function(callback) {
    if ($.support.cssTransitions) {
        return $(this).one(animationEndEvent, callback);
    } else {
        // defer execution for consistency between webkit/non webkit
        setTimeout(callback, 0);
        return $(this);
    }
};
@nonplus nonplus pushed a commit to nonplus/jquery-mobile that referenced this issue Oct 11, 2013
Stepan Riha Navigation: Only bind to browser's AnimationEnd event. Fixes #5156. 6244d94
@nonplus nonplus pushed a commit to nonplus/jquery-mobile that referenced this issue Oct 11, 2013
Stepan Riha Navigation: Only bind to browser's AnimationEnd event. Fixes #5156. b1ae271
@arschmitz arschmitz added a commit that referenced this issue Jan 22, 2014
@arschmitz arschmitz AnimationComplete: Add transition, fallbacks and remove memory leaks
Also no its own module including support tests for animations and
transitions

Fixes gh-5156
Fixes gh-6816
Fixes gh-6697
Fixes gh-6895
Fixes gh-6148
f4fbff2
@arschmitz arschmitz added a commit that referenced this issue Feb 12, 2014
@arschmitz arschmitz AnimationComplete: Add transition, fallbacks and remove memory leaks
Also no its own module including support tests for animations and
transitions

Fixes gh-5156
Fixes gh-6816
Fixes gh-6697
Fixes gh-6895
Fixes gh-6148
Closes gh-7001
0793219
@arschmitz arschmitz added a commit that closed this issue Feb 12, 2014
@arschmitz arschmitz AnimationComplete: Add transition, fallbacks and remove memory leaks
Also no its own module including support tests for animations and
transitions

Fixes gh-5156
Fixes gh-6816
Fixes gh-6697
Fixes gh-6895
Fixes gh-6148
Closes gh-7001
749c78e
@arschmitz arschmitz closed this in 749c78e Feb 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.