473,394 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

IE Error setInterval. (?)

Hello. My name is Josh, from the UK. I'm 16, and having a spot of bother with some javascript I've been working on over the past few days, that gives a sliding menu.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript">
  5. <!--
  6. menustatus = 'down';
  7. bouncecount = 10;
  8.  
  9. function AnimateMenu() {
  10.     //document.getElementById('menu').onClick = '';
  11.     ChangeHeight(0); 
  12.     menu = setInterval("ChangeHeight(1)", 30)
  13. }
  14.  
  15.  
  16. function GetMaxHeight(obj) {
  17.     contents = obj.childNodes;
  18.     contentnumber = contents.length;
  19.     maxheight = '';
  20.     for (i = 0; i < contentnumber; i++) {
  21.         currentnode = contents[i];
  22.         if (currentnode.nodeType == 1) {maxheight = maxheight*1 + parseInt(currentnode.style.height);}
  23.     }
  24.     return maxheight;
  25. }
  26.  
  27. function ToggleContents(obj) {
  28.     contents = obj.childNodes;
  29.     contentnumber = contents.length;
  30.     for (i = 1; i < contentnumber; i++) {
  31.         currentnode = contents[i]; 
  32.         if (currentnode.nodeType == 1 && menustatus == "down") {currentnode.style.visibility = 'hidden';}
  33.         else if (currentnode.nodeType == 1) {currentnode.style.visibility = 'visible';}
  34.     }
  35. }    
  36.  
  37. function ChangeHeight(repeat) {
  38.     container = document.getElementById('menu');
  39.     contents = container.childNodes;
  40.     contentnumber = contents.length;
  41.     button = container.firstChild.style;
  42.     for (i = 0; i < contentnumber; i++) {
  43.         if (contents[i].nodeType == 1) {minheight = parseInt(button.height); break;} 
  44.     }
  45.     if (menustatus == "up") {
  46.         height = parseInt(container.style.height);
  47.         maxheight = GetMaxHeight(container);
  48.         if (height < maxheight - 35) {newheight = height + 12}
  49.         else if (height < maxheight - 16) {newheight = height + 6}
  50.         else if (height < maxheight - 8) {newheight = height + 3}
  51.         else if (height < maxheight) {newheight = height + 1}
  52.         else if (height == maxheight) {
  53.             clearInterval(menu);
  54.             newheight = maxheight;
  55.             ToggleContents(container);
  56.             menustatus = "down";
  57.             button.cursor = 'url("Menu/Cursors/MenuUp.cur"), n-resize';
  58.             //container.onClick="AnimateMenu()";
  59.         }
  60.     }
  61.     else {
  62.         if (repeat == 0) {
  63.             ToggleContents(container); 
  64.             maxheight = GetMaxHeight(container); 
  65.             container.style.height = maxheight + "px";
  66.         }
  67.         height = parseInt(container.style.height);    
  68.         avail = height - minheight;        
  69.         if (avail > 100) {newheight = height - 12}        
  70.         else if (avail > 20) {newheight = height - 6}
  71.         else if (avail > 8) {newheight = height - 3}
  72.         else if (avail > 0) {newheight = height - 1}
  73.         else if (avail == 0) {
  74.             clearInterval(menu);
  75.             newheight = height;
  76.             menustatus = "up";
  77.             button.cursor = 'url("Menu/Cursors/MenuDown.cur"), n-resize';
  78.             //container.onClick="AnimateMenu()";
  79.         } 
  80.     }
  81.     container.style.height = newheight + "px";
  82.  
  83. }
  84.  
  85. -->
  86. </script>
  87.  
  88. <style type="text/css">
  89. #menu {
  90.     width:200px;
  91.     border:1px solid #000;
  92.     -moz-border-radius:10px;
  93. }
  94. #menu .first{
  95.     padding:0 2px;
  96.     margin:0;
  97.     border-bottom:1px solid #000;
  98.     cursor:url("Menu/Cursors/MenuUp.cur"), n-resize;
  99. }
  100. </style>
  101.  
  102. </head>
  103.  
  104. <body>
  105.  
  106. <div id="menu"><div id="1" class="first" style="height:20px;" onClick="AnimateMenu()"></div>
  107. <div id="2" style="height:20px;">hello world!</div>
  108. <div id="3" style="height:20px;">hello world!</div>
  109. <div id="4" style="height:20px;">hello world!</div>
  110. <div id="5" style="height:20px;">hello world!</div>
  111. <div id="6" style="height:20px;">hello world!</div>
  112. <div id="7" style="height:20px;">hello world!</div>
  113. <div id="8" style="height:20px;">hello world!</div>
  114. <div id="9" style="height:20px;">hello world!</div>
  115. </div>
  116. </body>
  117. </html>
Bit of a beast I'm afraid. The problem I'm having is that when I run this page in IE, the script will not stop - I'm guessing something has gone wrong with

clearInterval(menu)

...but IE's error messages points to

menu = setInterval("ChangeHeight(1)", 30)

I'm at a loss what to do. My debugger in IE isn't working. All works perfectly in Firefox.

Except, re-clicking on the button whilst the menu is mid-slide screws things - in FireFox, everything gets out of sync, and in IE movement gets faster and faster every time you click. Great fun (for the first and perhaps second time) but a pain in the ar$e. I've tried to get rid of the button's OnClick property, and reinstate it once everything has stopped, but this didn't seem to work. (Those lines commented out).

Any help would be much appreciated,

Josh Pencheon
Cambridge,
England.
Nov 13 '06 #1
3 2240
bobo
1
I may be mistaken (and late) but I believe setInterval's second parameter is measured in milliseconds and instructs the browser to repeat the call to the first argument with that interval. Thus you are repeatedly calling ChangeHeight every 30 milliseconds. If that is correct then you're probably overwhelming the browser with work.
Feb 10 '07 #2
dmjpro
2,476 2GB
is it running on firfox ......

because i don't know about firfox ....

in ie the window.setInterval is like this .....

var inter1 = window.setInterval(fun_ref,30)
var fun_ref = funtion(){
//ur code
}

at a condition ... window.clearInterval(inter1);

plz send me the reply .....
i am online
Feb 12 '07 #3
acoder
16,027 Expert Mod 8TB
setInterval is repeatedly called until it is stopped or the user exits the page.

See the following links:
http://developer.mozilla.org/en/docs...ow.setInterval
http://javascript.about.com/library/blstvsi.htm
Feb 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Richard A. DeVenezia | last post by:
At line this.timerId = setInterval (function(){this.step()}, 100) I get error dialog Error:Object doesn't support this property or method. If I change it to this.timerId = setInterval...
1
by: Weston C | last post by:
In the course of trying to build a simple clock, I've run into a problem using the setInterval (and setTimeout) function. http://weston.canncentral.org/misc/tkeep/tkeep.html...
17
by: George Hester | last post by:
Hoe can I use setInterval where its argument is a function which also has an argument? For example I have a function change(Msg) where Msg is dynamically generated and returns nothing at this point...
6
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I...
1
by: rajesh | last post by:
var fixedX = -1 // x position (-1 if to appear below control) var fixedY = -1 // y position (-1 if to appear below control) var startAt = 0 // 0 - sunday ; 1 - monday var showWeekNumber =...
3
by: shawn | last post by:
Hi All Was trying to get this bit of code working (simplified of course) for (i=0;i<uuid_num;i++) { window.setInterval(InitMap(uuidValues), timePeriod); } Where uuid_num, uuidValues,...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
2
by: shawnwperkins | last post by:
Hi Folks, I'm new to Javascript and just need a little help. I downloaded a script from Dynamic Drive's Web site and I'm trying to make a simple modification and could use some help. :) The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.