JQuery Callback Object Method usage instructions

Source: Internet
Author: User

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 ']);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.