The following code (see Fiddle here) throws the stack overflow referred to in the question title. I'm trying to get a box shadow to display around a circular image in a pulse effect. Can anyone point out the recursion, please? I'm very much a Javascript novice and can't see it. Thank you.
HTML
<div id="pulseDiv"> <a href="#" id="advisers-css-image"> <div id="advisersDiv"><img src="http://ubuntuone.com/1djVfYlV62ORxB8gSSA4R4"></div> </a> </div>
CSS
.pulse { box-shadow: 0px 0px 4px 4px #AEA79F; }
Javascript
function fadeIn() { $('#pulseDiv').find('div.advisersDiv').delay(400).addClass("pulse"); fadeOut(); }; function fadeOut() { $('#pulseDiv').find('div.advisersDiv').delay(400).removeClass("pulse"); fadeIn(); };
The call stack is limited in size, and when it's exceeded, the RangeError is thrown. This can happen when a deeply nested function is called, or when a lot of new variables are created. The most common way to fix this error is to reduce the number of function calls, or to limit the number of variables that are created.
The "RangeError: Maximum call stack size exceeded" error occurs when a function is called so many times that the invocations exceed the call stack limit. To solve the error, specify a base case that has to be met to exit the recursion.
It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit. This is almost always because of a recursive function with a base case that isn't being met.
The Uncaught RangeError is caused when the browser's hardcoded stack size is exceeded and the memory is exhausted. So, always ensure that the recursive function has a base condition that can stop its execution.
Your calls are made recursively which pushes functions on to the stack infinitely that causes max call stack exceeded error due to recursive behavior. Instead try using setTimeout which is a callback.
Also based on your markup your selector is wrong. it should be #advisersDiv
function fadeIn() { $('#pulseDiv').find('div#advisersDiv').delay(400).addClass("pulse"); setTimeout(fadeOut,1); //<-- Provide any delay here }; function fadeOut() { $('#pulseDiv').find('div#advisersDiv').delay(400).removeClass("pulse"); setTimeout(fadeIn,1);//<-- Provide any delay here }; fadeIn();
your fadeIn()
function calls the fadeOut()
function, which calls the fadeIn()
function again. the recursion is in the JS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With