[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/jquery/ui/ -> effect-bounce.js (source)

   1  /*!
   2   * jQuery UI Effects Bounce 1.13.3
   3   * https://jqueryui.com
   4   *
   5   * Copyright OpenJS Foundation and other contributors
   6   * Released under the MIT license.
   7   * https://jquery.org/license
   8   */
   9  
  10  //>>label: Bounce Effect
  11  //>>group: Effects
  12  //>>description: Bounces an element horizontally or vertically n times.
  13  //>>docs: https://api.jqueryui.com/bounce-effect/
  14  //>>demos: https://jqueryui.com/effect/
  15  
  16  ( function( factory ) {
  17      "use strict";
  18  
  19      if ( typeof define === "function" && define.amd ) {
  20  
  21          // AMD. Register as an anonymous module.
  22          define( [
  23              "jquery",
  24              "../version",
  25              "../effect"
  26          ], factory );
  27      } else {
  28  
  29          // Browser globals
  30          factory( jQuery );
  31      }
  32  } )( function( $ ) {
  33  "use strict";
  34  
  35  return $.effects.define( "bounce", function( options, done ) {
  36      var upAnim, downAnim, refValue,
  37          element = $( this ),
  38  
  39          // Defaults:
  40          mode = options.mode,
  41          hide = mode === "hide",
  42          show = mode === "show",
  43          direction = options.direction || "up",
  44          distance = options.distance,
  45          times = options.times || 5,
  46  
  47          // Number of internal animations
  48          anims = times * 2 + ( show || hide ? 1 : 0 ),
  49          speed = options.duration / anims,
  50          easing = options.easing,
  51  
  52          // Utility:
  53          ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
  54          motion = ( direction === "up" || direction === "left" ),
  55          i = 0,
  56  
  57          queuelen = element.queue().length;
  58  
  59      $.effects.createPlaceholder( element );
  60  
  61      refValue = element.css( ref );
  62  
  63      // Default distance for the BIGGEST bounce is the outer Distance / 3
  64      if ( !distance ) {
  65          distance = element[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3;
  66      }
  67  
  68      if ( show ) {
  69          downAnim = { opacity: 1 };
  70          downAnim[ ref ] = refValue;
  71  
  72          // If we are showing, force opacity 0 and set the initial position
  73          // then do the "first" animation
  74          element
  75              .css( "opacity", 0 )
  76              .css( ref, motion ? -distance * 2 : distance * 2 )
  77              .animate( downAnim, speed, easing );
  78      }
  79  
  80      // Start at the smallest distance if we are hiding
  81      if ( hide ) {
  82          distance = distance / Math.pow( 2, times - 1 );
  83      }
  84  
  85      downAnim = {};
  86      downAnim[ ref ] = refValue;
  87  
  88      // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
  89      for ( ; i < times; i++ ) {
  90          upAnim = {};
  91          upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
  92  
  93          element
  94              .animate( upAnim, speed, easing )
  95              .animate( downAnim, speed, easing );
  96  
  97          distance = hide ? distance * 2 : distance / 2;
  98      }
  99  
 100      // Last Bounce when Hiding
 101      if ( hide ) {
 102          upAnim = { opacity: 0 };
 103          upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
 104  
 105          element.animate( upAnim, speed, easing );
 106      }
 107  
 108      element.queue( done );
 109  
 110      $.effects.unshift( element, queuelen, anims + 1 );
 111  } );
 112  
 113  } );


Generated : Fri Nov 15 08:20:01 2024 Cross-referenced by PHPXref