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

Shake

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

描述 (Description)

Shake效果可以与effect()方法一起使用。 这会垂直或水平地多次抖动元素。

语法 (Syntax)

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

<i>selector</i>.effect( "shake", {arguments}, speed );

参数 (Parameters)

以下是所有论点的描述 -

  • times - 动摇时代。 默认值为3。

  • distance - 震动的距离。 默认值为20。

  • direction - 效果的方向。 可以是“向上”,“向下”,“向左”,“向右”。 默认为“左”

例子 (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" 
         src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js">
      </script>
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            $("#button").click(function(){
               $(".target").effect( "shake", {times:4}, 1000 );
            });
         });
      </script>
      <style>
         p {background-color:#bca; width:200px; border:1px solid green;}
         div{ width:100px; height:100px; background:red;}
      </style>
   </head>
   <body>
      <p>Click the button</p>
      <button id = "button"> Shake </button>
      <div class = "target">
      </div>
   </body>
</html>