Hi everbody,
I have a problem with the following code :
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".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); }
Can somebody help me to fix this code??


Reply With Quote