Last active
August 29, 2015 14:07
-
-
Save thomasdashney/fc34afdd85340b9b8e28 to your computer and use it in GitHub Desktop.
jQuery Element Blinking
This file contains hidden or 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
// set up flashing! | |
function blink($thingToBlink, numberOfTimesToBlink) { | |
if (!numberOfTimesToBlink) | |
numberOfTimesToBlink = -1; | |
$thingToBlink.addClass('blinking'); | |
// blink for 100ms | |
setTimeout(function() { | |
$thingToBlink.removeClass('blinking'); | |
// set it to blink again in 1 seconds | |
if (numberOfTimesToBlink) { // if still times to blink left | |
setTimeout(function() { | |
blink($thingToBlink, numberOfTimesToBlink-1) | |
}, 1000); | |
} | |
}, 150); | |
} | |
// example usage | |
blink($('#my-element'), 3); // blink 3 times |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment