當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JQuery UI jQuery.effects.define()用法及代碼示例

jQuery.effects.define( name [, mode ], effect )

返回:Function

添加的版本:1.12

說明:定義效果。

  • jQuery.effects.define( name [, mode ], effect )
    • name
      類型:String
      要創建的效果的名稱。
    • mode
      類型:String
      效果的默認模式。可能的值為 "show""hide""toggle"
    • effect
      類型:Function( Object options, Function done() )
      定義效果邏輯。 options 參數包含 durationmode 屬性,以及任何 effect-specific 選項。

定義與 .effect() .show() .hide() .toggle() 一起使用的新效果。使用 this 作為單個 DOM 元素調用效果方法。 done 參數必須在動畫完成時調用。

jQuery.effects.define() 將新效果存儲在 jQuery.effects.effect[ name ] 中並返回作為 effect 參數提供的函數。

例子:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.effects.define demo</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
  <style>
  .elem {
    position: absolute;
    width: 150px;
    height: 150px;
    background: #3b679e;
  }
  </style>
  <script src="//code.jquery.com/jquery-1.12.4.js"></script>
  <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
 
Click anywhere!
<div class="elem"></div>
 
<script>
$.effects.define( "fade", "toggle", function( options, done ) {
  var show = options.mode === "show";
 
  $( this )
    .css( "opacity", show ? 0 : 1 )
    .animate( {
      opacity: show ? 1 : 0
    }, {
      queue: false,
      duration: options.duration,
      easing: options.easing,
      complete: done
    } );
} );
 
$( document ).on( "click", function() {
  $( ".elem" ).toggle( "fade" );
} );
</script>
 
</body>
</html>

演示:

相關用法


注:本文由純淨天空篩選整理自jqueryui.com大神的英文原創作品 jQuery.effects.define()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。