2011-03-27 54 views
0

我正在尝试做一个背景颜色,该颜色在JavaScript中从颜色淡入淡出(或任何颜色),但我的代码无法使用。 Firebug中的错误说this.countDown.bind不是函数。但是我已经将countDown定义为一个函数,您可以在下面的代码中看到。请有人告诉我我做错了什么。这里是我的代码:淡入淡出的背景色与javascript无法合作

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> 

回答

0

this.countDown是一个JavaScript函数。因此,您没有任何子对象(即一个被称为绑定的对象)可以深入到。我错过了什么吗?