First I converted my existing styling to use CSS. If you aren't familiar with CSS, the easiest way to start experimenting with it is to put it between style tags in the head of your HTML document. The initial tag needs a type attribute to tell the browser what type of style information you are using, so it should look like this:
border: 2px solid black;
I hadn't previously included sizing information for the thumbnails, but I added a class called thumbs and set image tags in that class to set the size to 40px by 40px. This means that even if I accidentally load images that are too large or small for thumbnails, they will be forced to display in thumbnail size.
I also added a slideshow class to hold the entire slideshow. This will allow me to do things like add a border or change the background color for the whole slideshow if I desire. At this point I'm only using it to set the maximum height to the the height of the large image, because when I add more thumbnails I want them to stay on the side of the large image instead of moving above it. Unfortunately, Internet Explorer doesn't support the max-height attribute, so I'll still have to work on this issue more later.
Finally I created a style for the selected thumbnail. I decided that I wanted my selected thumbnail to be semi-transparent and have a narrow red border. Since only one image will be selected at a time I decided to use an id called "current" for this purpose. The advantage of using CSS is that I can change how it will look at any time without changing the code. The style looks like this:
border: 1px solid red;
Here we see some code to handle browser differences again, the standard calls for using a opacity element, but both IE and Mozilla-based browsers don't support that yet.
Finally, I changed the HTML for the thumbnails to use the styles and call my function. The HTML for my slideshow now looks like this:
<img class="thumbs" id="current" src="simone_thumb.jpg" onClick='document.getElementById("largeImage").src="simone.jpg"' alt="Thumbnail of Dog with EARTH Sticker"/>
<img class="thumbs" id="julie" src="julie_thumb.jpg" onClick='document.getElementById("largeImage").src="julie.jpg"' alt="Thumbnail of laptop with EARTH Sticker"/>
<img id="largeImage" src="simone.jpg" alt="Larger verson of selected thumbnail"/>
You can see a working example of the code so far here.
If you need a refresher (or first pass) at HTML and CSS, check out my favorite HTML and CSS book, HTML Dog: The Best-Practice Guide to XHTML and CSS and its accompanying website https://www.htmldog.com.
This site needs an editor - click to learn more!
You Should Also Read:
Editor's Picks Articles
Top Ten Articles
Content copyright © 2019 by Julie L Baumler. All rights reserved.
This content was written by Julie L Baumler. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.