緣由:用網頁版逛勇造的時候,搞不清楚眼前的勇造到底是白色還是具有透明效果
逛勇造的時候在瀏覽器開發者工具打下面這段,使背景顏色不斷變換,以利檢視具有透明效果之勇造
var loop=function g(t,d,f,a){setTimeout(function(){if(new Date().getTime()<t)g(t,d,f,a);else if(f&&!f(a))g(new Date().getTime()+d,d,f,a);},1);};
var breathingBackgroundColor=function (a){/* a[0]:int_as_counter ; a[1]:function to get target_DOM */ if(stop!=false)return true; let n=a[0]/1024*Math.PI;a[0]=(a[0]+1)%2048;let nR=(0x80+parseInt(Math.cos(n*3)*0x60)),nG=(0x80+parseInt(Math.cos(n*5)*0x60)),nB=(0x80+parseInt(Math.cos(n)*0x60)), tmpR=(nR%256).toString(16),tmpG=((nG)%256).toString(16),tmpB=((nB)%256).toString(16); let t=a[1](); if(t!=undefined) t.style.backgroundColor="#"+(tmpR+tmpG+tmpB).toUpperCase();};
var stop=false;
loop(0,11,breathingBackgroundColor,[0,function(){return document.getElementById("avatarList").childNodes[1]}]);
若要停止只需再打上
stop=1;
重啟則是
stop=false; loop(0,11,breathingBackgroundColor,[0,document.body]);
衍生使用
loop(0,11,breathingBackgroundColor,[0, /* 這一格填你如何得到要改背景顏色的DOM的function */ ]);
比方說我想改 document.body 那就填 function(){return document.body;}
你可能會問我為什麼不直接使用document.body就好,以它來說確實如此。
但逛勇造的時候,顯示勇造們的那個 DOM 會被移除,然後新的會放上去,而寫死的話會拿到舊的,也就被無效了。
所以採用每次更新顏色時重新拿 DOM 的方式
對了 巴哈官方可以考慮做個開關(?)