/jQuery UI


jQuery.effects.define( name [, mode ], effect )Returns: Functionversion added: 1.12

Description: Defines an effect.

Defines a new effect for use with .effect(), .show(), .hide(), and .toggle(). The effect method is invoked with this being a single DOM element. The done argument must be invoked when the animation is complete.

jQuery.effects.define() stores the new effect in jQuery.effects.effect[ name ] and returns the function that was provided as the effect parameter.


<!doctype html>
<html lang="en">
  <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">
  .elem {
    position: absolute;
    width: 150px;
    height: 150px;
    background: #3b679e;
  <script src="//code.jquery.com/jquery-1.12.4.js"></script>
  <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Click anywhere!
<div class="elem"></div>
$.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" );
} );


© The jQuery Foundation and other contributors
Licensed under the MIT License.