Skip to content

Instantly share code, notes, and snippets.

@danman01
Created August 7, 2019 16:23
Show Gist options
  • Save danman01/5cedaa948fc5ce76c15718c9fecbb75b to your computer and use it in GitHub Desktop.
Save danman01/5cedaa948fc5ce76c15718c9fecbb75b to your computer and use it in GitHub Desktop.
flash and hide jquery addition
// Extend jquery with flashing for elements
$.fn.flash = function(duration, iterations, hideAfter) {
duration = duration || 1000; // Default to 1 second
iterations = iterations || 1; // Default to 1 iteration
const iterationDuration = Math.floor(duration / iterations);
for (let i = 0; i < iterations; i++) {
this.fadeOut(iterationDuration).fadeIn(iterationDuration);
}
if (hideAfter) {
let hide = () => this.hide()
hide = hide.bind(this)
setTimeout(hide, hideAfter + iterations * duration)
}
// allow method chaining
return this;
}
module.exports = $.fn.flash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment