代码如下 | 复制代码 |
function tggg() { //$("#asd").css({ "background-color": "red" }).show().fadeOut(500); fadeColor( { r: 0, g: 255, b: 0 }, //star color {r: 255, g: 255, b: 255 }, //end color function (color) { document.getElementById( "asd" ).style.backgroundColor = color; }, 1, 10); } //所有代码的执行时间只有24毫秒左右。 function fadeColor(from, to, callback, duration, totalFrames) { //用一个函数来包裹setTimeout,根据帧数来确定延时 function doTimeout(color, frame) { setTimeout( function () { try { callback(color); } catch (e) { JSLog.write(e); } }, (duration * 1000 / totalFrames) * frame); //总持续秒数/每秒帧数*当前帧数=延时(秒),再乘以1000作为延时(毫秒) } // 整个渐变过程的持续时间,默认为1秒 var duration = duration || 1; // 总帧数,默认为持续秒数*15帧,也即每秒15帧 var totalFrames = totalFrames || duration * 15; var r, g, b; var frame = 1; //在第0帧设置起始颜色 doTimeout( 'rgb(' + from.r + ',' + from.g + ',' + from.b + ')' , 0); //计算每次变化所需要改变的rgb值 while (frame < totalFrames + 1) { r = Math.ceil(from.r * ((totalFrames - frame) / totalFrames) + to.r * (frame / totalFrames)); g = Math.ceil(from.g * ((totalFrames - frame) / totalFrames) + to.g * (frame / totalFrames)); b = Math.ceil(from.b * ((totalFrames - frame) / totalFrames) + to.b * (frame / totalFrames)); // 调用本frame的doTimeout doTimeout( 'rgb(' + r + ',' + g + ',' + b + ')' , frame); frame++; } }
|
火柴人绳索英雄2无限金币版 (Stickman Rope Hero 2)安卓版v2.2v3.4.2
下载奥特曼之格斗超人内测版本 安卓最新版v11.0.0
下载奥特曼之格斗超人百度版 安卓版v11.0.0
下载奥特曼之格斗超人4399游戏盒版 最新安卓版v11.0.0
下载德凯奥特曼D闪光剑模拟器 安卓版v1.0
德凯奥特曼D闪光剑模拟器是一个非常有趣的奥特曼变身模拟器,可
亚刻觉醒器 安卓版v1.1
亚刻觉醒器模拟器是一个非常有趣的奥特曼变身模拟器,为喜欢亚刻
海上餐厅无限金币版 v1.0
海上餐厅免广告版是游戏的破解版本,在该版本中为玩家去除了广告
阿西美女室友竟然全解锁版 v1.0.2
阿西美女室友竟然内置菜单版是游戏的破解版本,在该版本中为玩家
我是大东家正版 最新版v1.2.738
我是大东家正版是一款放置类模拟经营手游,玩家将回到古代成为家