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

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

@nonplus

Description

@nonplus

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);
    }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions