开发者

Fade background color not working with javascript

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜