Skip to content

Instantly share code, notes, and snippets.

@CreativeNotice
Last active December 26, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CreativeNotice/7144598 to your computer and use it in GitHub Desktop.
Save CreativeNotice/7144598 to your computer and use it in GitHub Desktop.
Simple function to pulsate element using jQuery animate.
/**
* pulsar
* @description Will change the element's opacity in a recursing manner.
* @param {Object} elm A DOM or jQuery element object
* @param {Object} options Options to override defaults, see var settings for those available
* @return {Void}
*
* @see jQuery.animate http://api.jquery.com/animate/
*/
var pulsar = function( elm, options ) {
// Set our defaults
var settings = $.extend({
prop_start: { opacity: 0.4 },
prop_end: { opacity: 1 },
duration: 1000,
easing: 'linear'
}, options );
// Animate that element
$( elm ).animate( settings.prop_start, settings.duration, settings.easing, function(){
$(this).animate( settings.prop_end, settings.duration, settings.easing, pulsar(this) );
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment