Home > Web Front-end > JS Tutorial > body text

About the practical application of jQuery Callback function

jacklove
Release: 2018-05-04 15:18:07
Original
1331 people have browsed it

We often see the callback function in our studies. This article will explain in detail how to use the callback function Callback.

jQuery Problems with animation

Many jQuery functions involve animation. These functions may take speed or duration as optional parameters.

Example:

$("p").hide("slow")
Copy after login

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

Example

$("button").click(function(){
$("p").hide(1000);
});
Copy after login

Since JavaScript statements (instructions) are executed one by one - in order, the statements after the animation may generate errors or page conflicts because the animation has not yet Finish.

To avoid this situation, you can add the Callback function in the form of parameters.

jQuery Callback function

When the animation is 100% complete, the Callback function is called.

Typical syntax:

$(selector).hide(speed,callback)
Copy after login

The callback parameter is a function that is executed after the hide operation is completed.

Error (no callback)

$("p").hide(1000);
alert("The paragraph is now hidden");
Copy after login

Correct (with callback)

$("p").hide(1000,function(){
alert("The paragraph is now hidden");
});
Copy after login

This article explains some usage of the callback function callback. I want to learn more about this. For knowledge, please pay attention to php Chinese website.

Related recommendations:

Detailed explanation of javscript's callback function

Usage of php regular preg_replace_callback function

php Callback Detailed explanation of callback function

The above is the detailed content of About the practical application of jQuery Callback function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!