淡化背景颜色不使用javascript

时间:2011-03-27 19:27:34

标签: javascript html

我正在尝试在javascript中执行从颜色变为白色(或任何颜色)的背景颜色,但我的代码不起作用。 Firebug中的错误说this.countDown.bind不是函数。但我已将countDown定义为函数,如下面的代码所示。请有人能告诉我我做错了什么。这是我的代码:

var fadingObject = {
    yellowColor: function(val){
        var r = 'ff', 
        g = 'ff', 
        b = val.toString(16),
        newval = '#' + r + g + b;

        return newval;
    },
    fade: function(id, start, finish){
        this.start = start;
        this.count = this.start;
        this.finish = finish;
        this.id = id;

        this.countDown = function(){
            this.count += 30;

            if(this.count >= this.finish){
                document.getElementById(this.id).style.background = 'transparent';
                this.countDown = null;
                return;
            }

            document.getElementById(this.id).style.backgroundColor = this.yellowColor(this.count);

            setTimeout(this.countDown.bind(this), 100);
        }
    }
};

HTML(如果需要):

<div id="one">
  <p>Take control and make writing fun and fast again. Snippets automate...</p>
</div>

1 个答案:

答案 0 :(得分:0)

this.countDown是一个javascript函数。因此,您没有要向下钻取的任何子对象(即一个名为bind的对象)。我错过了什么吗?