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.

76 lines
1.8 KiB

1 year ago
  1. /*!
  2. * jQuery UI Effects Shake 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: Shake Effect
  10. //>>group: Effects
  11. //>>description: Shakes an element horizontally or vertically n times.
  12. //>>docs: http://api.jqueryui.com/shake-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( "shake", function( options, done ) {
  29. var i = 1,
  30. element = $( this ),
  31. direction = options.direction || "left",
  32. distance = options.distance || 20,
  33. times = options.times || 3,
  34. anims = times * 2 + 1,
  35. speed = Math.round( options.duration / anims ),
  36. ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
  37. positiveMotion = ( direction === "up" || direction === "left" ),
  38. animation = {},
  39. animation1 = {},
  40. animation2 = {},
  41. queuelen = element.queue().length;
  42. $.effects.createPlaceholder( element );
  43. // Animation
  44. animation[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance;
  45. animation1[ ref ] = ( positiveMotion ? "+=" : "-=" ) + distance * 2;
  46. animation2[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance * 2;
  47. // Animate
  48. element.animate( animation, speed, options.easing );
  49. // Shakes
  50. for ( ; i < times; i++ ) {
  51. element
  52. .animate( animation1, speed, options.easing )
  53. .animate( animation2, speed, options.easing );
  54. }
  55. element
  56. .animate( animation1, speed, options.easing )
  57. .animate( animation, speed / 2, options.easing )
  58. .queue( done );
  59. $.effects.unshift( element, queuelen, anims + 1 );
  60. } );
  61. } );