Hey gang,
My use of the setInterval and clearInterval functions keeps giving me an unwanted loop which jams the program up. I've stripped away all but the essentials on the code so you can see the problem.
If you see the code below, after the condition clipht =>300, the else portion exec. and I get the alert "you have reached 300" BUT, the problem is the program executes one more call to rolldown() even though the timer is cleared!!?
I put in comments to draw your attention:
<script type="text/javascript" >
//NOTE VARIABLES DELCLARED OUTSIDE OF FUNCTIOINS
var active_menu=null;
var targetmenuid=null;
var clipht = 10;
var timerID;
window.onload=function()
{
function init()
{
//window.alert("inside function init");
var men_array=new Array();
var allelems=document.getElementsByTagName("*");
//window.alert("length of allelems" + allelems.length);
}
function closeoldmenu()
{
//window.alert("you are inside closeoldmenu");
if(active_menu)
{
active_menu.style.display = "none";
active_menu = null;
}
}
//HERE IS THE rolldown() FUNCTION THAT IS CALLED BUT ONCE TOO OFTEN!!
function rolldown()
{
window.alert("inside rolldown");
clipht=clipht + 50;
if(clipht <300)
{
//THIS ALERT SHOWS UP ON EACH LOOP
window.alert("inside clipht addition");
// active_menu.style.clip="rect(0px 300px" + clipht + "px 0px)";
}
else {
clearInterval(timerID);
clipht = 0;
//HERE IS THE STATEMENT THE FIRES WHEN clipht =>300
window.alert("you have reached 300");
}
}//end rolldown
</script>
What happens is I get the "you have reached 300", then I get one more "inside clipht addition" and then the program just stops!
I would appreciate any suggestions.
Bookmarks