无涯教程-jQuery - Shake方法函数

123 阅读1分钟

Shake效果可与Effect()方法一起使用。这将多次垂直或水平地摇动元素。

Shake - 语法

selector.effect( "shake", {arguments}, speed );

下面是对所有参数-的描述

  • times      -  摇晃时间。默认值为3。

  • distance  -  摇晃距离。默认值为20。

  • direction - 摇晃方向,可以是  "up", "down", "left", "right". 默认为"left"

Shake - 示例

下面是一个简单的示例,显示了此效果-的用法

<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>

这将产生以下输出-

参考链接

www.learnfk.com/jquery/effe…