You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.6 KiB

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