I'm trying to do a background color that fades from a color to white (or any color) in javascript, but my code doesn't work. The error in Firebug says this.countDown.bind
is not a function. But I've defined countDown
as a function as you can see in the code below. Please can someone show me where I'm doing wrong. Here's my code:
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){
开发者_StackOverflow 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 (if needed):
<div id="one">
<p>Take control and make writing fun and fast again. Snippets automate...</p>
</div>
this.countDown
is a javascript function. Therefore, you don't have any child objects (namely one called bind) to drill down to. Am I missing something?
精彩评论