Created
August 7, 2019 16:23
-
-
Save danman01/5cedaa948fc5ce76c15718c9fecbb75b to your computer and use it in GitHub Desktop.
flash and hide jquery addition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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