The Callback function executes after the current animation 100% is complete.
Problems with JQuery animations
Many jQuery functions involve animations. These functions may use speed or duration as an optional parameter.
Example:$ ("P"). Hide ("slow")
the speed or duration parameter can set many different values, such as "slow", "fast", "normal", or milliseconds.
tip: because JavaScript statements (directives) are executed one-by-in-order, the statements after the animation may produce errors or page conflicts because the animation is not yet complete.
To avoid this situation, you can add the Callback function as a parameter.
Instance
The following instances are callback functions after the hidden effect is fully implemented:
Use callback instance $ ("button"). Click (function () {
$ ("P"). Hide ("Slow", function () {
Alert ("The paragraph is now hidden");
});
});
Try
The following instance does not have a callback function, and the warning box pops up before the hidden effect is complete:
There is no callback (callback) $ ("button"). Click (function () {
$ ("P"). Hide (1000);
Alert ("The paragraph is now hidden");
});
Online example?
JQuery Callback method