Skip to content

Instantly share code, notes, and snippets.

@TiuTalk
Created September 4, 2012 17:44
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 TiuTalk/3624019 to your computer and use it in GitHub Desktop.
Save TiuTalk/3624019 to your computer and use it in GitHub Desktop.
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