Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

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

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

Comments

@nonplus
Copy link

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 pushed a commit to nonplus/jquery-mobile that referenced this issue Oct 11, 2013
nonplus pushed a commit to nonplus/jquery-mobile that referenced this issue Oct 11, 2013
arschmitz added a commit that referenced this issue Jan 22, 2014
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
arschmitz added a commit that referenced this issue Feb 12, 2014
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
idxbrokerAdmin added a commit to idxbroker/jquery-mobile that referenced this issue Jul 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant