Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Javascript image rotator - help!


Go to End


3 Posts   3048 Views

Avatar
Kaitar

Community Member, 3 Posts

20 April 2009 at 4:10am

So, I'm almost completely done with my very first SilverStripe customized template and site that I'm building for a client! Woo hoo!

However, I'm running into a problem, and I'm hoping that someone can help me with it.

I have a rotating image script on the top of the page that I'm working with, but I'm noticing that every time I change pages (for example, from home to about us) that the image rotation resets and goes back to the first image in the queue. I had originally fixed this on a non SS version of the site by using iframes, and having the content of those pages just display in the iframe, but I'm hoping that maybe there's a better way to do this without using iframes?

Thanks in advance!

Avatar
Hamish

Community Member, 712 Posts

23 April 2009 at 10:46am

...having the content of those pages just display in the iframe

Ouch. Putting everything into an iframe just to preserve rotation order seems extreme. You can't just randomize the start of the rotation?

Basically you have to let the server know where the rotation is. Eg, you intercept every link click and append a get get var (for example), or regularly submit a ping behind the users back with the current rotation that is saved in the users session, but without some sort of intervention the server has no way of knowing what is happening on the client.

Another creative solution - if you know that each image is display for 10 seconds, you could start the rotation at a position calculated from the current time. Eg, if there are 6 images, you could start at image n where [n] is the modulus of the current seconds in the minute / 10. Ie, everyone who hits the site at 0 seconds gets the first image, at 10 seconds the 2nd image, at 20 seconds the 3rd image etc. When you navigate away, you should theoretically get slotted back into the correct part of the sequence :)

Avatar
PHPUser

Community Member, 1 Post

1 March 2011 at 12:22pm

Kaitar - I was having the same problem... found this site and it was very helpful: http://www.sitepoint.com/forums/showthread.php?p=4820992#post4820992