PDA

View Full Version : Delay start of C Motion Gallery script?



procyan
12-17-2008, 10:55 PM
1) CMotion Image Gallery

2) http://www.dynamicdrive.com/dynamicindex4/cmotiongallery.htm

3) I love this script, thank you! I have set up the script to begin scrolling automatically, and I am wondering if it is possible to add a delay after the page loads, and before the images start to scroll. Any help with this will be much appreciated.

jscheuer1
12-18-2008, 05:18 AM
Yes, pretty much. A delay could be introduced (using the setTimeout() method) between when it is ready to scroll and when you cause it to scroll automatically. The specifics of that would depend upon what code you use to make it begin scrolling automatically. What code is that?

procyan
12-18-2008, 03:52 PM
I set this variable:

var running=1

jscheuer1
12-18-2008, 04:58 PM
I set this variable:

var running=1

That is not enough in and of itself to accomplish the task of setting cmotion into motion without user interaction. There must be other modifications to the code to support it, as running isn't even a variable in the default version of the cmotion script and has no relation to it. In fact, running being declared in that fashion almost certainly implies that it is later code that actually implements a directive to start moving, based upon running as a boolean flag.

So I probably still need to see the full code used for that, or perhaps even the entire modified script. It would be best (if it comes to that) if you would explain all modifications you made to the script to make it "begin scrolling automatically", and provide a link to a demo:

Please post a link to the page on your site that contains the problematic code so we can check it out.

That said, if we're lucky, you can just replace:


var running=1

with:


var running;
setTimeout(function(){running = 1;}, 1000);

where 1000 is the delay in milliseconds before the function in the timeout fires. But for the reasons mentioned, I seriously doubt that will work out well. Though anything is possible, depending upon the rest of the code.

procyan
12-18-2008, 05:59 PM
Thank you for your help with this!

A test page is loaded here: http://fletcherandwilder.com/tm/test.html

The Cmotion Gallery script is here: http://fletcherandwilder.com/tm/motiongallery2.js

I didn't think I did any modifications to the script at all.

You are right - the var running;
setTimeout(function(){running = 1;}, 1000); modification does not affect the script action.

procyan
12-18-2008, 06:04 PM
Actually, it does seem to be delaying now with that modification, I must not have cleared the cache correctly.

Thank you!

jscheuer1
12-18-2008, 06:14 PM
You didn't modify the script, I did. But you didn't mention you were using a version modified by someone else. Anyways, go back to just:


var running=1

Then at the end of the fillup function, find:


loadedyes=1
if (running){
scrollspeed=defaultspeed
moveleft()
}
}

Change it to:


loadedyes=1
if (running){
scrollspeed=defaultspeed;
fillup.timer = setTimeout(moveleft, 1000);
}
}

Where 1000 is the delay in milliseconds. You should also add here to both functions as shown:


function moveleft(){
if (iedom&&loadedyes){
if(fillup.timer)
clearTimeout(fillup.timer);
movestate="left"
if (parseInt(cross_scroll_0.style.left)<(-actualwidth))
cross_scroll_0.style.left=parseInt(cross_scroll_1.style.left)+actualwidth+"px"
if (parseInt(cross_scroll_1.style.left)<(-actualwidth))
cross_scroll_1.style.left=parseInt(cross_scroll_0.style.left)+actualwidth+"px"
cross_scroll_0.style.left=parseInt(cross_scroll_0.style.left)-scrollspeed+"px"
cross_scroll_1.style.left=parseInt(cross_scroll_1.style.left)-scrollspeed+"px"
//showhidediv("visible")
}
lefttime=setTimeout("moveleft()",100)
}

function moveright(){
if (iedom&&loadedyes){
if(fillup.timer)
clearTimeout(fillup.timer);
movestate="right"
if (parseInt(cross_scroll_0.style.left)>0)
cross_scroll_1.style.left=parseInt(cross_scroll_0.style.left)-actualwidth+"px"
if (parseInt(cross_scroll_1.style.left)>0)
cross_scroll_0.style.left=parseInt(cross_scroll_1.style.left)-actualwidth+"px"
cross_scroll_0.style.left=parseInt(cross_scroll_0.style.left)+scrollspeed+"px"
cross_scroll_1.style.left=parseInt(cross_scroll_1.style.left)+scrollspeed+"px"
}
righttime=setTimeout("moveright()",10)
}