|
| 1 | +<?xml version="1.0"?> |
| 2 | +<entries> |
| 3 | + <entry type="method" name="jQuery.effects.define" return="Function" added="1.12"> |
| 4 | + <title>jQuery.effects.define()</title> |
| 5 | + <signature> |
| 6 | + <argument name="name" type="String"> |
| 7 | + <desc>The name of the effect to create.</desc> |
| 8 | + </argument> |
| 9 | + <argument name="mode" type="String" optional="true"> |
| 10 | + <desc>The default mode for the effect. Possible values are <code>"show"</code>, <code>"hide"</code>, or <code>"toggle"</code>.</desc> |
| 11 | + </argument> |
| 12 | + <argument name="effect" type="Function"> |
| 13 | + <argument name="options" type="Object"/> |
| 14 | + <argument name="done" type="Function"/> |
| 15 | + <desc>Defines the effect logic. The <code>options</code> argument contains <code>duration</code> and <code>mode</code> properties, as well as any effect-specific options.</desc> |
| 16 | + </argument> |
| 17 | + </signature> |
| 18 | + <desc>Defines an effect.</desc> |
| 19 | + <longdesc> |
| 20 | + <p>Defines a new effect for use with <a href="/effect/"><code>.effect()</code></a>, <a href="/show/"><code>.show()</code></a>, <a href="/hide/"><code>.hide()</code></a>, and <a href="/toggle/"><code>.toggle()</code></a>. The effect method is invoked with <code>this</code> being a single DOM element. The <code>done</code> argument must be invoked when the animation is complete.</p> |
| 21 | + <p><code>jQuery.effects.define()</code> stores the new effect in <code>jQuery.effects.effect[ name ]</code> and returns the function that was provided as the <code>effect</code> parameter.</p> |
| 22 | + </longdesc> |
| 23 | + <example> |
| 24 | + <css><![CDATA[ |
| 25 | + .elem { |
| 26 | + position: absolute; |
| 27 | + width: 150px; |
| 28 | + height: 150px; |
| 29 | + background: #3b679e; |
| 30 | + } |
| 31 | +]]></css> |
| 32 | + <html><![CDATA[ |
| 33 | +Click anywhere! |
| 34 | +<div class="elem"></div> |
| 35 | +]]></html> |
| 36 | + <code><![CDATA[ |
| 37 | +$.effects.define( "fade", "toggle", function( options, done ) { |
| 38 | + var show = options.mode === "show"; |
| 39 | +
|
| 40 | + $( this ) |
| 41 | + .css( "opacity", show ? 0 : 1 ) |
| 42 | + .animate( { |
| 43 | + opacity: show ? 1 : 0 |
| 44 | + }, { |
| 45 | + queue: false, |
| 46 | + duration: options.duration, |
| 47 | + easing: options.easing, |
| 48 | + complete: done |
| 49 | + } ); |
| 50 | +} ); |
| 51 | +
|
| 52 | +$( document ).on( "click", function() { |
| 53 | + $( ".elem" ).toggle( "fade" ); |
| 54 | +} ); |
| 55 | +]]></code> |
| 56 | + </example> |
| 57 | + <category slug="effects-core"/> |
| 58 | + <category slug="effects"/> |
| 59 | + </entry> |
| 60 | +</entries> |
0 commit comments