[js] 簡易 color animate 實做
剛好手邊需要用到,作一個來玩玩。XD
目標是背景變成紅色轉白色,
這個網路上有jQuery color animate plug-in,
不過懶得載 jQuery 的話也可以自己作一個來玩。
usage::
color_animate(document.getElementById("testNode"));
以這種效果而言,只是數字加加減減要自己用心而已。
-----------------------------------------------------
function pad(str){return (str.length>1)?""+str:"0"+str;}
function getHex(r,g,b){
return "#"+pad(r.toString(16))
+pad(g.toString(16))
+pad(b.toString(16));
}
function color_animate(item){
var r=255,g=0,b=0;
item.style.background=getHex(r,g,b);
setTimeout(function(){
var tim=setInterval(function() {
g+=20;
b+=20;
item.style.background=getHex(r,g,b);
if(b>255){
item.style.background='';
clearInterval(tim);
}
}, 50);
},2000);
}
--
What do you want to have ? / What do you have?
從書本中,你可以發現我的各種興趣。
從CD中,你可以瞭解我所喜歡的偶像明星。
或許從文字你很難以瞭解一個人,但從物品可以。
My PPolis , My past. http://ppolis.tw/user/Tony
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 116.59.162.203
推
05/12 17:06, , 1F
05/12 17:06, 1F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章