我正在尝试在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>
答案 0 :(得分:0)
this.countDown
是一个javascript函数。因此,您没有要向下钻取的任何子对象(即一个名为bind的对象)。我错过了什么吗?