How to implement an automatic slide show with links
An updated version of this slide show script (published October 2010), providing cross browser fade effects (the fade effect used here only works with Internet Explorer) can be found here. This copy is maintained here for historical purposes only.
This article (and example) differ from the classic article "How to implement an automatic slide show", because behind each image is a link. There is an example of this on the right - click on the image to follow the link defined for that image (one is to a web page the other links just open the picture in the browser).
To achieve this effect three things are required:
- An image placeholder and link
- The images to be shown and links to be used
Firstly we need an image and a link, with the image inside the link. This is standard HTML for an image and link. It is the image (and link) used before the slide show starts. The only things to bare in mind are the height and width of the image must be pre-set and that the image and link must each be given unique ids. These are dealt with below under step 3. As an example, this page uses the following HTML for its image and link:
<a id="EmilyLink" href="http://www.cryer.co.uk/emily"> <img border="1" src="emily01.jpg" width="200" height="200" id="EmilyPicture" align="right"> </a>
If this script were to be used in a number of pages then it might be best included in a separate script file instead of being embedded directly in a web page.
The final step is to establish what images are to be shown as part of the slideshow, the links to go with them and how long each image is to be displayed before moving onto the next one. By way of illustration, this page uses the following:
defines the "
RunSlideShowWithLinks" function and
below the image placeholder.
1. pictureID The pictureID is the unique identifier given to the image. This identifies the image in which to run the slide show. This image will be replaced with each slide show image in turn. (The ID was specified as part of step 1 above "An image placeholder and link".) In the HTML the picture name is specified by including a statement of the form:id="pictureName"
2. linkID The linkID is the unique identifier given to the link. This identifies the link that is to be updated as the slide show runs. (The ID was specified as part of step 1 above "An image placeholder and link".) 3. imageLinks This is a string containing the names of the source files for each image to be displayed and the link to associate with each one. It should be build up containing the path to the image file, followed by a semi-colon, followed by the link that goes with the image, followed by a semi-colon then the next image and link pair and so on.
Note that the final semi-colon should be omitted. If you place a semi-colon at the end of the string then the slideshow will play through once and stop.
It is very important that each image is the same size (height and width) as the original - or that it has the same aspect ratio (ratio of height to width) as the original. This is because each image is loaded into the same area or space that the original image occupied. If this images are not the same size then the browser will stretch the image to fit (and for example thus give the impression of very fat or very thin people) and this may be undesirable.
So, in the example above, four images and four links are defined:
- emily01.jpg, with a link to http://www.cryer.co.uk/emily.
- emily02.jpg, with a link to the same image file.
- emily03.jpg, with a link to the same image file.
- emily04.jpg, with a link to the same image file.
4. displaySecs This is the number of seconds that each image is to be displayed for.