Latest web development tutorials

jQuery UI API – 轉移特效(Transfer Effect)

所屬類別

特效(Effects)

用法

描述:把一個元素的輪廓轉移到另一個元素。

transfer

参数 类型 描述
className String 转移的元素将接收的参数化的 class 名称。
to String jQuery 选择器,要转移到的元素。

當嘗試兩個元素之間的可視化交互時非常有用。

轉移的元素本身帶有class ui-effects-transfer ,其他的樣式需要由您來定義,比如添加背景或邊框。

實例

在綠色元素上點擊把它轉移到另一個元素。

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>轉移特效(Transfer Effect)演示</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <style>
  div.green {
    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;
  }
  .ui-effects-transfer {
    border: 1px dotted black;
  }
  </style>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>
 
<div class="green"></div>
<div class="red"></div>
 
<script>
$( "div" ).click(function() {
  var i = 1 - $( "div" ).index( this );
  $( this ).effect( "transfer", { to: $( "div" ).eq( i ) }, 1000 );
});
</script>
 
</body>
</html>