Background Image Slide Show
Did you know you can switch background images like a slide show?
Today, I was scanning the listings at
JavaScript Source
for ideas and creative stimulation, like I do sometimes. And
I saw JavaScript labeled as a background slide show. In
other words, the background image of the web page could be
switched to different images, in sequence. It intrigued me.
A background slide show is not something I had previously
thought about.
My imagination failed to come up with a reason why anyone
would want such a script. Except for fun.
Which is why I tried it.
The script appeared a bit rough, and it was able to image
switch only the web page body background. So I rewrote
it from scratch.
Here is a working example of the new script:
The new script can provide a slide show in any HTML tag that
can publish a background image. As examples, the HTML tag
could be a div, a table's td, a p paragraph tag, even the
body tag itself. But only one such tag per page (unless you
duplicate the JavaScript and modify it with a different
function name).
To use the script, provide a unique id value for whichever
HTML tag will have the background slide show. Then, specify
the value of that id in the JavaScript.
The JavaScript needs to be somewhere below the slide show tag.
CSS styles can be applied to the slide show tag, just like
you otherwise would to HTML tags. The example has inline
styles. A stylesheet may be used, instead.
Put the HTML tag with the background slide show where you
want the slide show to be. Here is the tag to reproduce the
above example.
Here is the JavaScript to reproduce the example. Put the JavaScript somewhere below the HTML tag it will affect.
The JavaScript can be customized for background image change
frequency, the id value of the HTML tag for the slide show,
and the images to be used in the slide show.
Comments in the Javascript are instructions for the customizations.
It is a fun little toy. Or a tool, if you have a serious use for it.
Question:
Did you find this article interesting and understandable? How can it be improved?
Your response is anonymous.
When done typing, click anywhere outside the box. [more info]
Will Bontrager
©2008 Bontrager Connection, LLC
Please note:
Articles on this website are presented "as is". However -
If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Ask one of our Experts and you'll have your answer!
Click here for details.