Results 1 to 1 of 1

Thread: Problem code for fading

  1. #1
    Member
    Join Date
    Jul 07
    Posts
    62

    Question Problem code for fading

    Hi everbody,

    I have a problem with the following code :

    Code:
    function Fade(fadeElement,fadeTimeSec)
    {
        this.fadeElement = fadeElement;
        this.fadeTime = fadeTimeSec * 1000;
        this.fadeTimeLeft = null;   
        this.fadeState = null;
        this.fadeTimerCurrent = null;  
        this.fadeTimerPassed = null;
        this.fadeTimer = null;
         
       if(this.fadeElement.FadeState == null)
       {
         if(this.fadeElement.style.opacity == null 
             || this.fadeElement.style.opacity == '' 
             || this.fadeElement.style.opacity == '1')
         {
           this.fadeElement.FadeState = 2;
         }
         else
         {
           this.fadeElement.FadeState = -2;
         }
       }
         
       if(this.fadeElement.FadeState == 1 || this.fadeElement.FadeState == -1)
       {
         this.fadeElement.FadeState = this.fadeElement.FadeState == 1 ? -1 : 1;
         this.fadeTimeLeft = this.fadeTime - this.fadeTimeLeft;
       }
       else
       {
         this.fadeElement.FadeState = this.fadeElement.FadeState == 2 ? -1 : 1;
         this.fadeTimeLeft = this.fadeTime;
         this.fadeTimer = setTimeout(this.animateFade(new Date().getTime(),this.fadeElement.id),33);
       }  
    }
    Fade.prototype.animateFade    = function(lastTick, eid)
    {  
        
       this.fadeTimerCurrent = new Date().getTime();
       this.fadeTimerPassed = this.fadeTimerCurrent - lastTick;
       
       var element = document.getElementById(eid);
      
       if(this.fadeTimeLeft <= this.fadeTimerPassed)
       {
         element.style.opacity = element.FadeState == 1 ? '1' : '0';
         element.style.filter = 'alpha(opacity = ' 
             + (element.FadeState == 1 ? '100' : '0') + ')';
         element.FadeState = element.FadeState == 1 ? 2 : -2;
         return;
         
       }
      
       this.fadeTimeLeft -= this.fadeTimerPassed;
       var newOpVal = this.fadeTimeLeft/this.fadeTime;
       if(element.FadeState == 1)
         newOpVal = 1 - newOpVal;
    
       element.style.opacity = newOpVal;
       element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
       
       this.fadeTimer = setTimeout(this.animateFade(this.fadeTimerCurrent,eid), 33);
    }
    The code is supposed to create a fading effect on a div or other element. But at this moment i get a javascript error : "Uncaught exception: RangeError: Maximum recursion depth exceeded".

    Can somebody help me to fix this code??
    Last edited by domentarion; Jul 9th, 2012 at 02:19 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •