Jump to:

3431 Posts in 1025 Topics by 864 members

Template Questions

SilverStripe Forums » Template Questions » Javascript image rotator - help!

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

Page: 1
Go to End
Author Topic: 2231 Views
  • Kaitar
    Avatar
    Community Member
    3 Posts

    Javascript image rotator - help! Link to this post

    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!

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Javascript image rotator - help! Link to this post

    ...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

  • PHPUser
    Avatar
    Community Member
    1 Post

    Re: Javascript image rotator - help! Link to this post

    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

    2231 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.