Forum Moderators: open

Message Too Old, No Replies

Auto Scrolling an Entire Screen

New to JS, need some help

         

fobinator

5:54 pm on Nov 23, 2004 (gmt 0)

10+ Year Member



I need some help with my implementation, I'll try to describe it as best I can. The closest thing I can think of is an arrivals/departure board at an airport.

I have a page with a table. This table can grow to any size. When the table only has enough values to fit a page, it's fine. When the table has enough information to span two pages, then I am trying to set intervals to show the first page for 10 sec, and then the (page down)second page for 10 sec, and so on...

The algorithm I am trying to do is:
1. Find the vertical scrolling for a page.
2. Based on the vertical scrolling, I pick an arbitrary number (I cannot find the size of pressing page down!) and try to determine the # of pages

// Determines how many pages
if (verticalscroll > 300)
{
for(i=0; i<=scrOfY; i=i+500)
{
pages = pages + 1;
}
}
3. Set a loop based on how many pages...

for(j=0; j <= pages; j++)
{
setInterval('window.scroll(0,"count")', 10000);
count = count + 500;
}

I'm having some trouble with the logic and getting this page to do what I want it to. Does anyone know of a better solution or what is wrong with mine? Also, this method is called onLoad()...

fobinator

10:03 pm on Nov 23, 2004 (gmt 0)

10+ Year Member



help?

adni18

12:47 pm on Nov 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have this on the web yet? If so, perhaps you could send me astickyMail [webmasterworld.com] with the url.

adni18

12:54 pm on Nov 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try replacing the following code:


for(j=0; j <= pages; j++)
{
setInterval('window.scroll(0,"count")', 10000);
count = count + 500;
}

with

currTmout=0;
for(j=0; j <= pages; j++)
{
currTmout=eval(eval(currTmout)+eval(10000));
window.setTimeout('window.scroll('+count+')', currTmout);
count = count + 500;
}

fobinator

5:49 pm on Nov 24, 2004 (gmt 0)

10+ Year Member



adni18,

thanks for responding, unfortunately I do not have this site up yet.

I tried what you suggested but it doesn't quite work right. It goes to the very top, waits 10 secs, then goes to the bottom. If the page is three screens long, then I will not see the second page. I found that the behavior that I want is something like this...

// I want this to run in an infinite loop and rotate...
while(1)
{
window.scroll(0 , count);

// This will stop the loop until I click ok
alert("Did I Move?");

// Divide the page equally
count = count + (scrOfY/pages);

// Reset the page
if(count > scrOfY)
count=0;

}

If I remove the "alert" everything goes crazy, putting in a "setTimeout" does not seem to work. Any ideas?

fobinator

6:11 pm on Nov 24, 2004 (gmt 0)

10+ Year Member



I actually found out why this wasn't working. setTimeout does not stop the js from running, it just sets an event to be run later....

This is the problem. I did find a script that actually makes the js stop and wait, but that script is breaking my machine. It breaks the other javascript in the page and causes IE to be unresponsive.

I know there's something wrong with my logic, since know I need this in a loop, can I just do a setTimeout on page load?

What's the difference between a setTimeout and a setInterval?

adni18

11:21 pm on Nov 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



a setInterval has the following kind of setup:

alert() [10 sec wait] alert() [10 sec wait] alert() ....

setInterval automatically sets a loop, seperated by an interval