Advertisement
Tomlacko

Make all html elements randomly blink, lol

Dec 31st, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var leafs = (function getLeafNodes(master) {
  2.     var nodes = Array.prototype.slice.call(master.getElementsByTagName("*"), 0);
  3.     var leafNodes = nodes.filter(function(elem) {
  4.         return !elem.hasChildNodes() || elem.innerText!="";
  5.     });
  6.     return leafNodes;
  7. })(document);
  8.  
  9. for(var i=0; i<leafs.length; i++) {
  10.     var el = leafs[i];
  11.     el.funOn = (Math.random()+0.1)*2;
  12.     el.funOff = (Math.random()+0.1)*2;
  13.     el.funT = 0;
  14.     el.funState = el.style.visibility==="hidden"?"disabled":true;
  15. }
  16. var td = 100;
  17. function doFun() {
  18.     for(var i=0; i<leafs.length; i++) {
  19.         var el = leafs[i];
  20.         el.funT+=td/1000;
  21.         if(el.funT>=el.funOn && el.funState===true) {
  22.             el.funT = 0;
  23.             el.funState=false;
  24.             el.style.visibility="hidden";
  25.         }
  26.         else if(el.funT>=el.funOff && el.funState===false) {
  27.             el.funT = 0;
  28.             el.funState=true;
  29.             el.style.visibility="visible";
  30.         }
  31.     }
  32.     setTimeout(doFun, td);
  33. }
  34. setTimeout(doFun, td);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement