View Full Version : inserting a pause into a function

08-01-2002, 01:00 PM

Can anyone help me, how to insert a pause into my scrolling script (or into any script)?
The execution of the script should stop for a few seconds, then continue.
This migt complicate it even more: In the scroller script, I have integrated an if-then function, and if a particular object (an array) exists the scroller script begins to rotate images as well. The pause should only occur, if the if-then function returns true, so that the viewer has enough time to view the photos.

Thank you all, a million times!


08-01-2002, 01:40 PM
gimme a link to ur site and i'll see what i can do

08-01-2002, 02:47 PM
Here is the scroller script, but it is only a part of the whole, and some lines are in Hungarian, sorry! I really don't want to waste your time, going through my 300+ lines of code. I've copied only the part that does the scrolling.

It is quite flexible, you can set direction, speed, stop it, set the layer to be scrolled.

One way to slow it would be to set in scrollTimer instead of 1, a higher number. But then, the movement would be too jagged. The best solution would be, if the just after the testing for the existance of image links on the layer, you could insert a pause.

If you need the whole code:


and http://ortofamily.dns2go.com/huglass/munka/webre/javit/proba/minden3.js

Thank you all!!!!

// scrolling script starts -->

// Translation: ir/rany=dir, seb/sebesseg=speed, loop=loop, reteg = layer to be moved

k = -1;
function gorog(ir, seb, loop, reteg) {
loop = true;
irany = "fel";
sebesseg = 1;
scrolltimer = null;
ret = reteg;
if (document.layers) {
var page = eval(document.layers[ret]);
else {
if (document.getElementById) {
var page= eval("document.getElementById(ret).style");
else {
if (document.all) {
var page = eval(document.all.ret.style);
irany = ir;
sebesseg = parseInt(seb);
var y_pos = parseInt(page.top);
var x_pos = parseInt(page.left);
// if there are links to images on the layer, they have to be rotated
var tombnev = reteg + "kepek";
//checks, if there are image links on the layer
if ((tombnev == "kapcsol98kepek") || (tombnev == "madridkepek") || (tombnev == "szimp99kepek") || (tombnev == "szimpoz97kepek") || (tombnev == "kiallit96kepek") || (tombnev == "usakepek")) {
//If only I could insert a pause here...
var selector = (eval(y_pos)-140)/40*-1;
var egesz = Math.floor(selector) + 1;
var egeszelotti = eval(egesz) -1;
var egeszutani = eval(egesz) +1;
tombnevreal = eval(tombnev);
tombhosszreal = eval(tombnevreal.length);
var j = eval(egesz) *5;
if ((tombhosszreal -6 < j ) && (irany = "le")){
// loop = false, the scroll changesdirection, it goes up now (irany = direction, fel = up)
irany = "fel";
if ((k != j) && (tombhosszreal -6 > j )){
var tombnev = reteg + "kepek";
tombnevarr = eval(tombnev);
var adott = reteg +"belso" + egesz;
var adottelotti = reteg +"belso" + egeszelotti;
var adottutani = reteg +"belso" + egeszutani;
// this part is just for highlighting the selected link
WM_swapLayerBgcolor(adott,'#ccffff solid 1px','red');
// the kepreszab function displays the images, on another layer
// if there are no images to rotate, the scroll continues here
if (loop == true) {
if (irany == "le") {
page.top = (y_pos - (sebesseg));
} else {
if (irany == "fel" && y_pos < 130) {
page.top = (y_pos + (sebesseg));
} else {
if (irany == "bal" && x_pos > -800) {
page.left = (x_pos - (sebesseg));
} else {
if (irany == "jobb" && x_pos < 260) {
page.left = (x_pos + (sebesseg));
} else {
if (irany == "top") {
page.top = 10;
scrolltimer = setTimeout("gorog(irany,sebesseg,true,ret)", 1);
function stopgorog() {
loop = false;
// scrolling script ends -->

08-01-2002, 02:49 PM
Just one more note:

Go into 2000 mmm.transglass.hu Madrid -> then "Mutargyak", on the page, to see where I would like to insert the pause.

(Works on NS4+, IE4+)

08-03-2002, 12:26 AM
The simplest solution would be to split your function into two seperate functions, and then call the second with setTimeout().

If there are any local variables in the first function that you would need in the second, you can pass them as arguments.

Hope that helps.

08-03-2002, 01:19 PM
i dunno, it might only stop the loading of images, but not the scrolling itself. The scroller invokes the image changes, on another layer.

But, the scroller can e stopped by calling the stopgorog() function.
So I would insert in a separate function a stopgorog() then a
setTimeout{(stargorog()), 5000}

Normally startgorog (the scrolling script) takes 5 parameters, if I don't give it any parameters, it should continue with the same ones, that it used before it was stopped. If not I will have an error... :mad:
Will try this, tomorrow

08-05-2002, 05:55 PM
I've found the solution:
Just after the image swap, I change the loop to false, which stops the scroll.
THen with a setTimeout, I restart the scroll.

08-05-2002, 10:07 PM
Make sure you use clearTimeout() when needed!

08-06-2002, 01:30 AM
Thank you.
Yes indeed sometimes, two or more calls to the same function resulted in some strange "effects"...