effects.pulsate.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * jQuery UI Effects Pulsate 1.7.2
  3. *
  4. * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * http://docs.jquery.com/UI/Effects/Pulsate
  9. *
  10. * Depends:
  11. * effects.core.js
  12. */
  13. (function($) {
  14. $.effects.pulsate = function(o) {
  15. return this.queue(function() {
  16. // Create element
  17. var el = $(this);
  18. // Set options
  19. var mode = $.effects.setMode(el, o.options.mode || 'show'); // Set Mode
  20. var times = o.options.times || 5; // Default # of times
  21. var duration = o.duration ? o.duration / 2 : $.fx.speeds._default / 2;
  22. // Adjust
  23. if (mode == 'hide') times--;
  24. if (el.is(':hidden')) { // Show fadeIn
  25. el.css('opacity', 0);
  26. el.show(); // Show
  27. el.animate({opacity: 1}, duration, o.options.easing);
  28. times = times-2;
  29. }
  30. // Animate
  31. for (var i = 0; i < times; i++) { // Pulsate
  32. el.animate({opacity: 0}, duration, o.options.easing).animate({opacity: 1}, duration, o.options.easing);
  33. };
  34. if (mode == 'hide') { // Last Pulse
  35. el.animate({opacity: 0}, duration, o.options.easing, function(){
  36. el.hide(); // Hide
  37. if(o.callback) o.callback.apply(this, arguments); // Callback
  38. });
  39. } else {
  40. el.animate({opacity: 0}, duration, o.options.easing).animate({opacity: 1}, duration, o.options.easing, function(){
  41. if(o.callback) o.callback.apply(this, arguments); // Callback
  42. });
  43. };
  44. el.queue('fx', function() { el.dequeue(); });
  45. el.dequeue();
  46. });
  47. };
  48. })(jQuery);