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>