The Callback function executes after the current animation 100% completes.
Problems with JQuery animation
Many jQuery functions involve animations. These functions may use speed or duration as optional parameters.
Example:
The code is as follows |
Copy Code |
$ ("P"). Hide ("slow") |
Speed or duration parameters can set many different values, such as "slow", "fast", "normal", or milliseconds.
Instance
The code is as follows |
Copy Code |
$ ("button"). Click (function () { $ ("P"). Hide (1000); }); |
Try it for yourself.
Because JavaScript statements (instructions) are executed one at a--in order, the statements after the animation may produce errors or page conflicts because the animation is not finished.
To avoid this situation, you can add the Callback function as a parameter.
The code is as follows |
Copy Code |
var foo = function (value) { Console.log (this); Console.log (' foo: ' + value); }; var bar = function (value) { Console.log (' bar: ' + value); }; var callbacks = $. Callbacks (); Adding the Foo method to the callbacks queue Callbacks.add (foo); To join the bar method in the callbacks queue Callbacks.add (bar); Cancel Callback Callbacks.disable (); Delete all callback methods Callbacks.empty (); The argument list is returned to the callback list Callbacks.fire (' foo '); Use Callbacks.fired () to determine if a callback in the list returns true at least once by calling, false Console.log (callbacks.fired ()); var myobj = { }; /* Access to all callbacks in the given context and parameter list Context: A callback in this list is triggered by a contextual reference Args: A parameter or parameter list is passed back to the callback list * * Callbacks.firewith (myobj, [' foo ']); /** * To determine if there is a callback function in the callback list */ Console.log (Callbacks.has (foo)); A list of callbacks that are locked in its current state. Callbacks.lock (); Call callback object Invalid after locking Callbacks.firewith (myobj, [' foo ']); A list of callbacks that determine whether they have been locked. Lock returns True, non-lock return False Console.log (callbacks.locked ()); Deletes a collection of callback or callback callback lists. Callbacks.remove (foo) Callbacks.firewith (myobj, [' foo ']); |