当前位置: 首页 > 文档资料 > jQuery 入门教程 >

stop([clearQueue, gotoEnd ])

优质
小牛编辑
119浏览
2023-12-01

描述 (Description)

stop( [clearQueue, gotoEnd ])方法停止所有指定元素上当前运行的所有动画。

语法 (Syntax)

以下是使用此方法的简单语法 -

<i>selector</i>.stop( [clearQueue], [gotoEnd] ) ;

参数 (Parameters)

以下是此方法使用的所有参数的说明 -

  • clearQueue - 这是可选的布尔参数。 设置为true时清除动画队列,有效地停止所有排队的动画。

  • gotoEnd - 这是可选的布尔参数。 布尔值(true/false),当设置为true时,会立即完成当前正在播放的动画,包括在show上重置原始样式并隐藏和调用回调函数。

例子 (Example)

以下是一个简单的例子,简单地显示了这种方法的用法 -

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            $("#go").click(function(){
               $(".target").animate({left: '+=100px'}, 2000);
            });
            $("#stop").click(function(){
               $(".target").stop();
            });
            $("#back").click(function(){
               $(".target").animate({left: '-=100px'}, 2000);
            });
         });
      </script>
      <style>
         p {background-color:#bca; width:250px; border:1px solid green;}   
         div{position: absolute; left: 50px; top:300px;}
      </style>
   </head>
   <body>
      <p>Click on any of the following buttons:</p>
      <button id = "go"> GO</button>
      <button id = "stop"> STOP </button>
      <button id = "back"> BACK </button>
      <div class = "target">
         <img src = "/jquery/images/jquery.jpg" alt = "jQuery" />
      </div>
   </body>
</html>