"-//W3C//DTD HTML 4.01 Transitional//EN"
"Content-Type" content= "text/html; charset=UTF-8" >
背景颜色渐变
"Button1" type= "button" value= "button" onclick= "tggg()" />
function tggg() {
fadeColor(
{ r: 0, g: 255, b: 0 },
{r: 255, g: 255, b: 255 },
function (color) { document.getElementById( "asd" ).style.backgroundColor = color; }, 1, 10);
}
function fadeColor(from, to, callback, duration, totalFrames) {
function doTimeout(color, frame) {
setTimeout( function () {
try {
callback(color);
} catch (e) { JSLog.write(e); }
}, (duration * 1000 / totalFrames) * frame);
}
var duration = duration || 1;
var totalFrames = totalFrames || duration * 15; var r, g, b; var frame = 1;
doTimeout( 'rgb(' + from.r + ',' + from.g + ',' + from.b + ')' , 0);
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));
doTimeout( 'rgb(' + r + ',' + g + ',' + b + ')' , frame); frame++;
}
}
"width: 600px; height: 200px; border: 1px solid red;" id= "asd" >
脚本之家欢迎各位光临--http:
|