Нет описания

effect-bounce.js 2.5KB

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