Spec-Zone.ru › jQuery UI

jQuery.effects.define()

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

Description: Defines an effect.

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

    • name
      Type: String
      The name of the effect to create.
    • mode
      Type: String
      The default mode for the effect. Possible values are "show", "hide", or "toggle".
    • effect
      Type: Function( Object options, Function done() )
      Defines the effect logic. The options argument contains duration and mode properties, as well as any effect-specific options.

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.

Example:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.effects.define demo</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.3/themes/smoothness/jquery-ui.css">
  <style>
  .elem {
    position: absolute;
    width: 150px;
    height: 150px;
    background: #3b679e;
  }
  </style>
  <script src="https://code.jquery.com/jquery-3.7.1.js"></script>
  <script src="https://code.jquery.com/ui/1.13.3/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>

Demo:

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jqueryui.com/jQuery.effects.define

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API