On the jQuery callback function

Callback functions are executed after the current animation 100% complete.
issue jQuery animation.
Many jQuery functions involved in animation.
These functions will probably speed or duration as an optional parameter.
Examples: $ ( "P") hide ( "Show").
Speed duration or a number of different parameter values can be provided, such as "slow", "fast", "normal" or milliseconds.
Example:
$ ( "Button") the Click (function () {.
$ ( "P") hide (1000).
});

Because JavaScript statement (instruction) is executed one by one - in the order, the statement after the animation may generate an error page or conflict, because the animation is not yet complete.

To avoid this situation, you can add Callback function as a parameter.

jQuery Callback function

When the animation is 100% complete, which calls Callback function.
Typical Syntax:
$ (Selector) .hide (Speed, the callback)
the callback parameter is a function executed in a hide after the operation is completed.

There are cases of callback:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
  $("p").hide(2000,function(){
  alert("The paragraph is now hidden");
  });
  });
});
</script>
</head>
<body>
<button type="button">Hide</button>
<p>This is a paragraph with little content.</p>
</body>
</html>



The first instance of the callback function, a warning box will pop up after the completion of the hidden effect.
No case of callback:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
  $("p").hide(2000);
  alert("The paragraph is now hidden");
  });
});
</script>
</head>
<body>
<button type="button">Hide</button>
<p>This is a paragraph with little content.</p>
</body>
</html>
第二个实例没有回调函数,警告框会在隐藏效果完成前弹出。



Published 74 original articles · won praise 27 · views 9507

Guess you like

Origin blog.csdn.net/qq_42526440/article/details/102140816