Created
September 4, 2012 17:44
-
-
Save TiuTalk/3624019 to your computer and use it in GitHub Desktop.
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
var blink = { | |
delay: function() { | |
return Math.random() * 8000 + 2000; | |
}, | |
duration: function() { | |
return 100 + Math.floor(Math.random() * 100); | |
}, | |
blinkAgain: function() { | |
return (Math.random() < .2); | |
}, | |
betweenBliks: function() { | |
return blink.duration() / 2; | |
} | |
}; | |
$.fn.blink = function(continueBlinking) { | |
var $element = $(this); | |
// Star the blink | |
$element.addClass('blink'); | |
// Finish the blink | |
setTimeout(function() { | |
$element.removeClass('blink'); | |
// Change of blinking again | |
if (blink.blinkAgain()) { | |
setTimeout(function() { | |
$element.blink(false); | |
}, blink.betweenBliks()); | |
} | |
}, blink.duration()); | |
// Continue blinking? | |
if (continueBlinking) { | |
setTimeout(function() { | |
$element.blink(true); | |
}, blink.delay()); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment