PageRenderTime 46ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/stop/index.html

https://github.com/lastpetit/jqapi-br
HTML | 95 lines | 85 code | 10 blank | 0 comment | 0 complexity | 463b9560ff76dbd4240515731b973a15 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html lang='en'><head><meta http-equiv='content-type' content='text/html; charset=UTF-8' /></head><body>
  3. <div class="entry-content">
  4. <div class="entry-title roundTop">
  5. <h1 class="jq-clearfix">.stop()</h1>
  6. <div class="entry-meta jq-clearfix">
  7. Categories:
  8. <span class="category"><a href="http://api.jquery.com/category/effects/" title="View all posts in Effects">Effects</a> &gt; <a href="http://api.jquery.com/category/effects/custom-effects/" title="View all posts in Custom">Custom</a></span>
  9. </div>
  10. </div>
  11. <div id="stop1" class="entry method">
  12. <h2 class="jq-clearfix roundTop section-title">
  13. <span class="name">.stop( [ clearQueue ], [ jumpToEnd ] )</span> <span class="returns">Returns: <a class="return" href="http://api.jquery.com/Types/#jQuery">jQuery</a></span>
  14. </h2>
  15. <div class="jq-box roundBottom entry-details">
  16. <p class="desc"><strong>Description: </strong>Stop the currently-running animation on the matched elements.</p>
  17. <ul class="signatures"><li class="signature" id="stop-clearQueue-jumpToEnd">
  18. <h4 class="name">
  19. <span class="versionAdded">version added: <a href="/category/version/1.2/">1.2</a></span>.stop( [ clearQueue ], [ jumpToEnd ] )</h4>
  20. <p class="arguement"><strong>clearQueue</strong>A Boolean indicating whether to remove queued animation as well. Defaults to <code>false</code>.</p>
  21. <p class="arguement"><strong>jumpToEnd</strong>A Boolean indicating whether to complete the current animation immediately. Defaults to <code>false</code>.</p>
  22. </li></ul>
  23. <div class="longdesc">
  24. <p>When <code>.stop()</code> is called on an element, the currently-running animation (if any) is immediately stopped. If, for instance, an element is being hidden with <code>.slideUp()</code> when <code>.stop()</code> is called, the element will now still be displayed, but will be a fraction of its previous height. Callback functions are not called.</p>
  25. <p>If more than one animation method is called on the same element, the later animations are placed in the effects queue for the element. These animations will not begin until the first one completes. When <code>.stop()</code> is called, the next animation in the queue begins immediately. If the <code>clearQueue</code> parameter is provided with a value of <code>true</code>, then the rest of the animations in the queue are removed and never run.</p>
  26. <p>If the <code>jumpToEnd</code> property is provided with a value of <code>true</code>, the current animation stops, but the element is immediately given its target values for each CSS property. In our above <code>.slideUp()</code> example, the element would be immediately hidden. The callback function is then immediately called, if provided.</p>
  27. <p>The usefulness of the <code>.stop()</code> method is evident when we need to animate an element on <code>mouseenter</code> and <code>mouseleave</code>:</p>
  28. <pre>&lt;div id="hoverme"&gt;
  29. Hover me
  30. &lt;img id="hoverme" src="book.png" alt="" width="100" height="123" /&gt;
  31. &lt;/div&gt;</pre>
  32. <p>We can create a nice fade effect without the common problem of multiple queued animations by adding <code>.stop(true, true)</code> to the chain:</p>
  33. <pre>$('#hoverme-stop-2').hover(function() {
  34. $(this).find('img').stop(true, true).fadeOut();
  35. }, function() {
  36. $(this).find('img').stop(true, true).fadeIn();
  37. });</pre>
  38. <blockquote><p>Animations may be stopped globally by setting the property <code>$.fx.off</code> to <code>true</code>. When this is done, all animation methods will immediately set elements to their final state when called, rather than displaying an effect.</p></blockquote>
  39. </div>
  40. <h3>Example:</h3>
  41. <div class="entry-examples" id="entry-examples"><div id="example-0">
  42. <h4><span class="desc">Click the Go button once to start the animation, then click the STOP button to stop it where it's currently positioned. Another option is to click several buttons to queue them up and see that stop just kills the currently playing one.</span></h4>
  43. <pre class="prettyprint"><code class="example demo-code">&lt;!DOCTYPE html&gt;
  44. &lt;html&gt;
  45. &lt;head&gt;
  46. &lt;style&gt;div {
  47. position: absolute;
  48. background-color: #abc;
  49. left: 0px;
  50. top:30px;
  51. width: 60px;
  52. height: 60px;
  53. margin: 5px;
  54. }
  55. &lt;/style&gt;
  56. &lt;script src="http://code.jquery.com/jquery-git.js"&gt;&lt;/script&gt;
  57. &lt;/head&gt;
  58. &lt;body&gt;
  59. &lt;button id="go"&gt;Go&lt;/button&gt;
  60. &lt;button id="stop"&gt;STOP!&lt;/button&gt;
  61. &lt;button id="back"&gt;Back&lt;/button&gt;
  62. &lt;div class="block"&gt;&lt;/div&gt;
  63. &lt;script&gt;
  64. // Start animation
  65. $("#go").click(function(){
  66. $(".block").animate({left: '+=100px'}, 2000);
  67. });
  68. // Stop animation when button is clicked
  69. $("#stop").click(function(){
  70. $(".block").stop();
  71. });
  72. // Start animation in the opposite direction
  73. $("#back").click(function(){
  74. $(".block").animate({left: '-=100px'}, 2000);
  75. });
  76. &lt;/script&gt;
  77. &lt;/body&gt;
  78. &lt;/html&gt;</code></pre>
  79. <h4>Demo:</h4>
  80. <div class="demo code-demo"></div>
  81. </div></div>
  82. </div>
  83. </div>
  84. </div>
  85. </body></html>