Jquery animation Problems
Many jquery functions involve animation. These functions maySpeedOrDurationAs an optional parameter.
Example:$ ("P"). Hide ("slow ")
SpeedOrDurationParameters can be set to many different values, such as "slow", "fast", "normal", or millisecond.
Instance
$ ("Button"). Click (function (){
$ ("P"). Hide (1000 );
});
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.
Jquery callback function
Call the callback function when animation 100% is complete.
Typical Syntax:
$ (Selector). Hide (speed, callback)
CallbackA parameter is a function that is executed after the hide operation is complete.
Error (no callback)
$ ("P"). Hide (1000 );
Alert ("the paragraph is now hidden ");
Correct (with callback)
$ ("P"). Hide (1000, function () {alert ("the paragraph is now hidden ");});
Conclusion:If you want to execute a statement after an animation function, use the callback function.