jquery.ui.effect-pulsate.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*!
  2. * jQuery UI Effects Pulsate v1.9 stable
  3. * http://jqueryui.com
  4. *
  5. * Copyright 2012 jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. *
  9. * http://api.jqueryui.com/pulsate-effect/
  10. *
  11. * Depends:
  12. * jquery.ui.effect.js
  13. */
  14. (function( $, undefined ) {
  15. $.effects.effect.pulsate = function( o, done ) {
  16. var elem = $( this ),
  17. mode = $.effects.setMode( elem, o.mode || "show" ),
  18. show = mode === "show",
  19. hide = mode === "hide",
  20. showhide = ( show || mode === "hide" ),
  21. // showing or hiding leaves of the "last" animation
  22. anims = ( ( o.times || 5 ) * 2 ) + ( showhide ? 1 : 0 ),
  23. duration = o.duration / anims,
  24. animateTo = 0,
  25. queue = elem.queue(),
  26. queuelen = queue.length,
  27. i;
  28. if ( show || !elem.is(":visible")) {
  29. elem.css( "opacity", 0 ).show();
  30. animateTo = 1;
  31. }
  32. // anims - 1 opacity "toggles"
  33. for ( i = 1; i < anims; i++ ) {
  34. elem.animate({
  35. opacity: animateTo
  36. }, duration, o.easing );
  37. animateTo = 1 - animateTo;
  38. }
  39. elem.animate({
  40. opacity: animateTo
  41. }, duration, o.easing);
  42. elem.queue(function() {
  43. if ( hide ) {
  44. elem.hide();
  45. }
  46. done();
  47. });
  48. // We just queued up "anims" animations, we need to put them next in the queue
  49. if ( queuelen > 1 ) {
  50. queue.splice.apply( queue,
  51. [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
  52. }
  53. elem.dequeue();
  54. };
  55. })(jQuery);