Jquery callback object method instructions

Source: Internet
Author: User

This article introduces how to use callback objects in jquery. I hope this tutorial will be helpful to you.

The Callback function is executed after the current animation 100% is complete.
JQuery animation Problems
Many jQuery functions involve animation. These functions may use speed or duration as optional parameters.

Example:

The Code is as follows: Copy code
$ ("P"). hide ("slow ")

The speed or duration parameter can be set with many different values, such as "slow", "fast", "normal", or millisecond.

Instance

The Code is as follows: Copy code

$ ("Button"). click (function (){
$ ("P"). hide (1000 );
});

Try it yourself

Because JavaScript statements (commands) are executed one by one in order, the animated statements may produce errors or page conflicts because the animation is not completed yet.

To avoid this problem, 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 ();
// Add the foo Method to the callbacks queue
Callbacks. add (foo );
// Add the bar method to the callbacks queue
Callbacks. add (bar );
// Cancel callback
// Callbacks. disable ();
// Delete All callback Methods
// Callbacks. empty ();

// Return the parameter list to the callback list
Callbacks. fire ('foo ');
// Use callbacks. fired () to confirm. If the callback in the list is called at least once, true is returned; otherwise, false is returned.
// Console. log (callbacks. fired ());

Var myObj = {
};
/* Access all callbacks in the given context and parameter list
Context: context Reference of the callback triggered in the list
Args: a parameter or parameter list is returned to the callback list */
Callbacks. fireWith (myObj, ['foo']);
/**
* Check whether the callback function exists in the callback list.
*/
Console. log (callbacks. has (foo ));
// The list of callbacks that are locked in the current status.
// Callbacks. lock ();
// The callback object is invalid after the lock.
// Callbacks. fireWith (myObj, ['foo']);
// Check whether the callback list is locked. True is returned for locking. false is returned for non-locking.
// Console. log (callbacks. locked ());
// Delete the set of callback or 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.