2011-03-27 4 views
0

J'essaye de faire une couleur de fond qui passe d'une couleur au blanc (ou à n'importe quelle couleur) en javascript, mais mon code ne fonctionne pas. L'erreur dans Firebug dit this.countDown.bind n'est pas une fonction. Mais j'ai défini countDown comme une fonction que vous pouvez voir dans le code ci-dessous. S'il vous plaît, quelqu'un peut-il me montrer où je me trompe? Voici mon code:Couleur de fondu de fondu ne fonctionnant pas avec 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 (si nécessaire):

<div id="one"> 
    <p>Take control and make writing fun and fast again. Snippets automate...</p> 
</div> 

Répondre

0

this.countDown est une fonction javascript. Par conséquent, vous n'avez aucun objet enfant (à savoir un objet appelé bind) à explorer. Est-ce que je manque quelque chose?