public
Created

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
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());
}
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.