treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] How to change DIV background image every 5 seconds?

  • Hey!

    First post, my apologies if something like this has been answered, or if it's a stupid question. I have been searching and cannot find the ebst solution to this problem! (I am assuming this a a javascript fix? But I could be wrong)

    The idea is that there will be a background image of a <div> that changes every 5 seconds.

    Currently, I have an image of width: 1600px that changes every 5 seconds, however when the window is too small, it creates scrollbars as it is not truly a background. I want to have the image as a background, centered, so any excess on the right and left will be left offscreen with no scroll bars.

    Any ideas???

  • rather than a div containing an image how about setting the background with css then centring it with the position parameter's with no set width your issue with scroll bars should disappear until it hits actual content.

    As for changing it every five seconds take a look at jquery setTimeout function

  • What about adding a min-width to that background, and use overflow:hidden?

  • Aha! Thanks to both of you! Got it!