home > web design > photo swap with JavaScript
Photo-swapping in-class exercise
printable version (.pdf)
We’ll use Photoshop Elements to create a couple of thumbnail images, then Dreamweaver to present them in a webpage with user-activated JavaScript to swap photos in layout. Here’s an example of what your page might look like:
http://www.pages.drexel.edu/~corseel/graphics/whales.html.
Create thumbnails
- Download 3 photos (splash, tail, and spy) to LOCAL site “info652\images” folder (right-click on link and “save link as” or “save target as,” depending on your browser), from:
http://www.pages.drexel.edu/~corseel/graphics/
- Launch Photoshop Elements and open tail.jpg and spy.jpg (from where you just stored them)
- Create a thumbnail (150x110 pixels) for each tail.jpg and spy.jpg
- Either:
- Try Image menu, resize (only change the pixel dimensions; if grayed out, check “resample” box); or
- Try Rectangular marquee, pre-set to correct size (change mode to “fixed”; 150x110 pixels); Copy; Create new document with 150x110 pixel size (File menu; New); Paste
- “Save for web” as tail-sm.jpg and spy-sm.jpg, also in LOCAL site, “info652\images” folder. You should now have five new .jpg files in your local “info652/images” folder (the three originals, plus the two new thumbnails)
Create new page from template
- In Dreamweaver, with preferences and site set up, from File menu, select New
- Click Templates tab, choose “colx2”; confirm “Update page” is checked, click create
- From File menu, select Save As and save as whales.html in your site
- Update doc title in design view
- Update or remove breadcrumb navigation line
- Add h1 text about whales
- Save and upload all to dunx1 (upload all 5 photos, plus whales.html)
Insert image
- IMPORTANT: Confirm that image files are in your /652/images folder!
- Place cursor in left column of document
- Click “Insert Image” button (it’s a picture of a tree)
OR select Image from Insert menu
- Browse to images folder and select one thumbnail; click OK
- Always add <alt> text; click OK
- Add 2nd thumbnail under first
- Give both thumbnails a “name” attribute (perhaps “sm1” and “sm2”)
- Add large “splash.jpg” to main section of page (“name”=big)
***On the property inspector, the “name” attribute for images is here (unlabeled box with text “sm1”):

Your page should now look something like this:

JavaScript behaviors
We want a mouseover on a small photo to display its larger version in the big photo area, so we’ll add JS behaviors to both small photos.
- In Dreamweaver, with whales.html open for editing, open the Behaviors panel from the Window menu
- Select the element that will be used to trigger the behavior: the thumbnail “tail” photo (make sure all 3 photos have valid “name” attribute)
- Click the plus sign in Behaviors panel to add “Swap Image”
- Select image: “big” (that’s where the new image will appear)
- Set source to: “tail.jpg”
- Confirm that “preload” and “restore” are both checked; click okay
- Save whales.html
- Preview in browser to confirm all is as expected
- Repeat for 2nd thumbnail; save
- Examine XHTML source to see JavaScript generated by Dreamweaver
Finally
- Confirm your new page has a good title
- Add attribution to NOAA, linked to their site
- Upload whales.html, plus all FIVE photos to dunx1
- Check your page from http://www.pages.drexel.edu/~username/652/whales.html