元素透明 渐变函数

var testObj = document.getElementById("你想要渐变的元素");
function setOpacity(value) {
    testObj.style.opacity = value/10;
    testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
}
for (var i=0;i<11;i++) {
    setTimeout('setOpacity('+i+')', 100*i);
}
透明度的值范围0~10
 
 
 
下面方法将一个元素的颜色由黄色渐变为白色
var fade = function (node) {
    var level = 1;
    var step = function ( ) {
        var hex = level.toString(16);
        node.style.backgroundColor = '#FFFF' + hex + hex;
        if (level < 15) {
            level += 1;
            setTimeout(step, 100);
        } 
    };
    setTimeout(step, 100);
};
fade(document.body);
原文地址:https://www.cnblogs.com/chuangweili/p/5166038.html