Advertisement
here2share

HTML blinkText

Dec 11th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.92 KB | None | 0 0
  1. <div id="blinkText"></div>
  2.  
  3. <script>
  4. // Takes text to blink and id of element to blink text in
  5. function blinkText(text, id) {
  6.     // Blink interval
  7.     setInterval(blinker, 250);
  8.  
  9.     // Flag to see what state text is in (true or false)
  10.     var flag = true;
  11.  
  12.     // Number of times to blink text
  13.     var blinkNum = 50;
  14.     var i = 1;
  15. //you can select whole div by ajax
  16.     var divID = document.getElementById(id);
  17.  
  18.     function blinker() {
  19.         if (i < blinkNum) {
  20.            if (flag) {
  21.                divID.innerHTML = text;
  22.                flag = false;
  23.            } else {
  24.                divID.innerHTML = "";
  25.                flag = true;
  26.            }
  27.  
  28.            i++;
  29.        } else {
  30.            // Delete if still showing
  31.            divID.innerHTML = "";
  32.  
  33.            // Stop blinking
  34.            clearInterval(blinker);
  35.        }
  36.    }
  37. }
  38.  
  39. blinkText("Hello World", "blinkText");
  40. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement