Home >Web Front-end >JS Tutorial >The use of stop() in jquery
Purpose: In order to understand the usage of stop(), let’s take an example and see it in an intuitive way.
Physical object: A p with id="animater" contains a piece of text. (animator is used below to represent the actual object)
The final complete effect of the animation: animater moves to the right 800px (this complete process is animation 1), then, the font gradually becomes larger (this complete process is animation 2), then, the transparency gradually decreases to 0 (this complete process is animation 3), and then the transparency gradually returns to 1 (This complete process is animation 4), and then the font size becomes 16px and moves to a position 200px from the left border (this complete process is animation 5).
#Operation: Click on the buttons with different IDs to watch the effect.
##HTML code:
##
<p id="animater"> stop()方法测试 </p>
<p id="button"> <input type="button" id="button1" value="stop()"/> <input type="button" id="button2" value="stop(true)"/> <input type="button" id="button3" value="stop(false,true)"/> <input type="button" id="button4" value="stop(true,true)"/> </p>
CSS code:
#animater{ width: 150px; background:activeborder; border: 1px solid black; /*为了移动,需设置此属性*/ position: relative; }
// 为了看效果,随意写的动画 $('#animater').animate({ 'right':-800 }, 3000).animate({'font-size':'16px'},'normal').animate({'font-size':'26px'},'normal').animate({'font-size':'36px'},'normal').animate({'font-size':'46px'},'normal').animate({'font-size':'56px'},'normal').animate({'opacity':0},'normal').animate({'opacity':1},'normal').animate({'left':200,'font-size':'16px'},'normal'); // 点击不同的button执行不同的操作 $('#button1').click(function(){ //默认参数是false,不管写一个false还是两个false还是没写false效果一样 $('#animater').stop(); }); $('#button2').click(function(){ //第二个参数默认false $('#animater').stop(true); }); $('#button3').click(function(){ $('#animater').stop(false,true); }); $('#button4').click(function(){ $('#animater').stop(true,true); });
W3School has this description of: stop(
stopAll,goToEnd)
Optional. Specifies whether to stop all queued animations of the selected element. | |
Optional. Specifies whether the current animation is allowed to complete. |
This parameter can only be used when the stopAll parameter is set.
|
The above is the detailed content of The use of stop() in jquery. For more information, please follow other related articles on the PHP Chinese website!