Advertisement
DaCurse

JS Blink

Feb 20th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Element.prototype.blink = function(i) {
  2.   var self = this;
  3.   this.lastDisplay = this.style.display;
  4.   this.change = true;
  5.   this.blinkInterval = setInterval(function() {
  6.     if (self.change) self.style.display = 'none';
  7.     else self.style.display = self.lastDisplay;
  8.     self.change = !self.change;
  9.   }, i);
  10. }
  11.  
  12. Element.prototype.stopBlink = function() {
  13.     if(this.blinkInterval) clearInterval(this.blinkInterval);
  14. }
  15.  
  16. document.getElementById('b').blink(60);
  17. document.getElementById('b').stopBlink();
  18.  
  19. // Fiddle: https://jsfiddle.net/5d2s5La8/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement