March 19, 2008
|
|
|
|
|
|
I like simplicity, especially with code. After wasting hours trying to tweak a flashy image rotation Javascript, complete with .js files to include, I gave up, called up the Google, and found this wonderfully simple code from a throwaway response on an online forum:
Here’s how it works. See the div labelled “home-photo”? That wraps around the image that is to be replaced with other images. The img tag within the home-photo div has its own id=”photo” element which, no surprise, is called in the var ImageHolder1 = If you want to change the id=photo element to, say, id=xyz then you just change ‘photo’ to ‘xyz’ in the var ImageHolder1 = document.getElementById(’xyz’) line. (By the way, ‘var’ is shorthand for variable. You’re just setting a variable that grabs the element tagged id=”xyz”.)
To specify the images to rotate, just add file path and image names to the var ImageArr1 = new Array(”", “”, “”) line. Be careful to wrap each file path and image name with double quotes with a comma between each and you’ll be fine.
The last element to set is the ‘3500′ at the end of the window.setTimeout(..) line. That’s the number of milliseconds between the display of each image.
This code does not have fancy wipes, dissolves, or other whizzy features. But it doesn’t require include references to javascript files and other complexity that can go horribly wrong horribly fast. Just tweak this code and drop the Javascript part at the bottom of your web pages or templates (so it doesn’t get in the way of search bots). The image, the “home-photo” div in this example, goes where it goes in your design.
|
Leave a Reply