473,388 Members | 1,391 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,388 software developers and data experts.

setInterval different for both IE and FF.

Hello

I am very new to advanced JS programming and am looking for some insight.
My experience is in PHP/MySql so I am familiar with programming fundamentals, but by far not an expert.

I created a script that will take a variable number of divs wrapped in a main div and then scroll them vertically non-stop, like a slot-machine.

I develop mainly on FF and had the script working as expected. I then went to IE and noticed that the scrolling action was slower. I set the interval to 50. I experimented with different amounts because I read in a previous article here that FF and IE refresh at a different ms rate. The results where the same.

I also noticed that as the images scroll, if I move the mouse around the screen across links and such the scrolling seems to be a bit jerky and hesitant.

Here is the code I have.

Expand|Select|Wrap|Line Numbers
  1. <script type='text/javascript'>
  2.     var div_obj = []; // Will hold all the div objects
  3.     var scroll_id; // For clearing the setInterval
  4.     var total_div_height = 0; // Holds the height of all the divs for repositioning
  5.     var wrapper = document.getElementById('wrapper'); // The main holding div
  6.     var wrapper_height = parseInt(wrapper.style.height); // Holds holding div height
  7.  
  8.     initializeDivs(); // Preposition the divs now.
  9.  
  10.     // We will stack the divs from bottom to top and overflow out the top.
  11.     function initializeDivs() {
  12.         var children = wrapper.childNodes;
  13.         var div_height = []; // Holds individual div heights
  14.         // Preset the first div_top to the bottom of the wrapper.
  15.         // Since we are positioning by (top) this would place it below the wrapper, we will subtract the div_height
  16.         // from it later on for proper positioning
  17.         var div_top = wrapper_height;
  18.         var idx = 0;
  19.         for(x in children) { // Walk thru the children
  20.             var name = children[x].nodeName;
  21.             // Make sure we only process the <div> tags
  22.             if(name == 'DIV') {
  23.                 // Load up the div objects into a global array for use in scroll()
  24.                 div_obj[idx] = children[x];
  25.  
  26.                 // Determine the height of each div to position it properly
  27.                 div_height[idx] = parseInt(children[x].style.height);
  28.  
  29.                 // Add up each div height in a global var to use in scroll()
  30.                 total_div_height = total_div_height + div_height[idx];
  31.  
  32.                 // Position each div in relation to the bottom
  33.                 // The height of the div will be subtracted to position by top
  34.                 // We will then decrement by each new div to stack them
  35.                 div_top = (div_top - div_height[idx]);
  36.                 children[x].style.top = div_top + 'px';
  37.                 idx++;
  38.             }
  39.         }
  40.     }
  41.  
  42.     // The divs will scroll down
  43.     function scroll() {
  44.         for(x in div_obj) {
  45.             var top_pos = parseInt(div_obj[x].style.top);
  46.             if(top_pos <= wrapper_height){
  47.                 div_obj[x].style.top = top_pos + 1 + 'px';
  48.             } else {
  49.                 div_obj[x].style.top = (wrapper_height - total_div_height) + 'px';
  50.             }
  51.         }            
  52.     }
  53.     function startScroll() {
  54.         scroll_id = setInterval("scroll()", 50);
  55.     }
  56.     function stopScroll() {
  57.         clearInterval(scroll_id);   
  58.     }
  59. </script>
  60.  
The startScroll is called with onload and onmouseout
stopScroll is called with onmouseover.

Now each div that is being scrolled is a table construction with an image sized by the browser. That may account for the hesitant behavior, I am not sure.

Any help here would be appreciated, especially if what I wrote could of been done in a more efficient algorithm.

Oh and the site with the active script is:
http://njeatsnow.com/1index.php

Thanks
Scotty
Jul 4 '10 #1
1 1895
gits
5,390 Expert Mod 4TB
the more nodes are involved and the more DOM operations you do - the more time it will consume. of course the performance will differ in different browsers - i guess the best performance should be achieved with chromium/chrome. the interval time will of course depend on that performance ... there might be different optimal settings for different browsers ... so basically avoid nodes and DOM operation wherever you can ... you could even retrieve the nodes onload already so that you just use references instead of always retrieving them during every step - you could optimize it by creating lookup-maps etc. ...

kind regards
Jul 12 '10 #2

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

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
1
by: Robert Mark Bram | last post by:
Howdy All! I would like to find since when did different versions of browsers and/or JavaScript/JScript/ECMAScript support the SetTimeout and SetInterval methods.. this is for compatibility...
5
by: Richard A. DeVenezia | last post by:
Is some future Mozilla going to support setInterval ( <function:function>, <interval:number> ) ? Right now it seems to be simply setInterval ( <function-text:string>, <interval:number> ) --...
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...
6
by: david epsom dot com dot au | last post by:
I have a report with an OLE bound frame. A bitmap has been pasted into the bound field. The bitmap displays and prints differently on different computers. In particular, the alignment is...
4
by: barry | last post by:
If The script below is exeuted from the onload="startit()" in the body tag everything works fine but when I remove the onload and try to execute by using the attributes.add from within the Page_Load...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
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,...
2
by: Mirko Vogt | last post by:
Hey, it seems that the socket-module behaves differently on unix / windows when a timeout is set. Here an example: # test.py import socket...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.