jquery-ui/ui/jquery.effects.pulsate.js

64 lines
1.4 KiB
JavaScript
Raw Normal View History

/*
* jQuery UI Effects Pulsate @VERSION
*
2011-01-17 14:13:18 +00:00
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* http://docs.jquery.com/UI/Effects/Pulsate
*
* Depends:
* jquery.effects.core.js
*/
(function( $, undefined ) {
2008-06-04 02:34:33 +00:00
$.effects.effect.pulsate = function( o ) {
return this.queue( function( next ) {
2011-03-06 23:45:43 +00:00
var elem = $( this ),
mode = $.effects.setMode( elem, o.mode || "effect" ),
show = mode === "show" || elem.is( ":hidden" ),
showhide = ( show || mode === "hide" ),
// showing or hiding adds an extra "half" animation
anims = ( ( o.times || 5 ) * 2 ) + ( showhide ? 1 : 0 ),
duration = o.duration / anims,
2011-03-06 23:45:43 +00:00
animateTo = 0,
queue = elem.queue(),
queuelen = queue.length,
i;
if ( show ) {
elem.css( "opacity", 0 ).show();
animateTo = 1;
}
// anims - 1 opacity "toggles"
for ( i = 1; i < anims; i++ ) {
elem.animate({
opacity: animateTo
2011-03-06 23:45:43 +00:00
}, duration, o.easing );
animateTo = 1 - animateTo;
}
elem.animate({
opacity: animateTo
2011-03-06 23:45:43 +00:00
}, duration, o.easing, function() {
if ( animateTo === 0 ) {
elem.hide();
}
if ( o.complete ) {
o.complete.apply( this );
}
});
// We just queued up "anims" animations, we need to put them next in the queue
if ( queuelen > 1) {
queue.splice.apply( queue,
[ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
}
next();
});
};
})(jQuery);