jQuery 特效 - 傳輸特效



描述

Transfer 效果可以與 effect() 方法一起使用。它將元素的輪廓傳輸到另一個元素。在嘗試視覺化兩個元素之間的互動時非常有用。

語法

以下是使用此效果的簡單語法:

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

引數

以下是所有引數的描述:

  • className - 可選,傳輸元素將接收的類名。

  • to - jQuery 選擇器,要傳輸到的元素。

示例

以下是一個簡單的示例,展示了此效果的使用:

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://tutorialspoint.tw/jquery/jquery-3.6.0.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() {

            $("div").click(function () {
               var i = 1 - $("div").index(this);
               $(this).effect("transfer",{ to: $("div").eq(i) }, 500);
            });
				
         });
			
      </script>
		
      <style>
         div.green { margin: 0px; width: 100px; height: 80px; background: green; 
            border: 1px solid black; position: relative; }
				
         div.red { margin-top: 10px; width: 50px; height: 30px; background: red; 
            border: 1px solid black; position: relative; }
				
         /* Following is required  to show border while transferring.*/
         .ui-effects-transfer { border: 2px solid black; }
      </style>
		
   </head>
	
   <body>
      <p>Click any of the squares:</p>
		
      <div class = "green"></div>
      <div class = "red"></div>
   </body>
</html>

這將產生以下結果:

jquery-effects.htm
廣告

© . All rights reserved.