Advertisement
rplantiko

A JavaScript text-decoration:blink implementation

May 2nd, 2012
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.   "text-decoration:blink" usually is the horror for any webpage
  4.  
  5.   See http://theworldsworstwebsiteever.com/ for a demonstration.
  6.  
  7.   There is an exception where I found it reasonable:
  8.   I had the requirement of a countdown which should start to blink during its final 30 seconds.
  9.   This makes sense to me.
  10.  
  11.   I use the CSS class
  12.     .blink {
  13.        text-decoration:blink;
  14.        }
  15.  
  16.   which doesn't work for IE, Chrome and Safari, however.
  17.  
  18.   For basic JS-DOM functions I am using minlib.js ( see http://ruediger-plantiko.net/minlib/ )
  19.  
  20.  
  21. */
  22.       function Blinker(e) {
  23.         this.e = getElement(e);
  24.         var theBlinker = this;
  25.         this.id = window.setInterval( function() {
  26.           theBlinker.blink();          
  27.           }, Blinker.interval );
  28.         }
  29.       Blinker.prototype.blink = function() {
  30.         var visibility = this.e.style.visibility;
  31.         if (this.e.className.match(/\bblink\b/)) {
  32.           this.e.style.visibility = (visibility == "hidden") ? "" : "hidden";
  33.           }
  34.         else {
  35.           this.stop();
  36.           }  
  37.         };
  38.       Blinker.prototype.stop = function() {
  39.         this.e.style.visibility = "";
  40.         window.clearInterval( this.id );
  41.         };  
  42.       Blinker.interval = 700;  
  43.        
  44. // Buttons for test page, setting and resetting the "blink" class        
  45.       function setBlinker(e) {
  46.         setClass(byId("test"),"blink");
  47.         if (navigator.userAgent.match(/MSIE|Chrome|Safari/)) {
  48. // Need a Blinker instance as soon as the new class is set
  49.           new Blinker("test");
  50.           }
  51.         }  
  52.       function resetBlinker(e) {
  53.         resetClass(byId("test"),"blink");
  54.         }  
  55.        
  56.       function doOnLoad() {
  57.         registerFor( byId("setBlink"), "click", setBlinker );
  58.         registerFor( byId("resetBlink"), "click", resetBlinker );  
  59.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement