JQuery learning(6):JQuery callback function

来源:互联网 发布:whois数据库 编辑:程序博客网 时间:2024/05/22 12:55

The  callback function execution after current animation finishing 100%.

JQuery animation issue

A lot of functions of jQuery refer to animation

These functions may be will the speed or duration as optional parameter.

Example:$("p").hide("slow")

The parameters both speed and duration can be setting many different values, such as "slow", "fast", "normal"  or millisecond。

Example

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


Because of javascript sentence execute line-by-line,After the animation sentence may be  generate a error or conflict of page, for the animation not done. 

In order to avoid this case,you can add the callback function as parameters.

JQuery callback functions

After animation finish percent 100, invoke the callback function at once.

The typical syntax:

$(selector).hide(speed,callback)


The callback parameter is a function of be executed after the hide.

Error:(Without callback)

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


Right:(There is callback)

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

 

原创粉丝点击