Photo By Suzzie J
Today’s widget is an Image Strip, it has a lot of real uses, but the way I like too use it is for fancy visual effects.
Check out the fancy image viewer below. Make sure to pick an image thats a lot large then the current image (start with 9 or 10).
As you can see, an image strip matched with a bit of animation makes for a very nice looking effect (The images by Josh Gomez don’t hurt either). These sort of tricks are really nice for times when you want to look like your using Flash without actually using it.
The basic idea is you take div give it a height and width set its overflow to hidden and then use it as a viewport. You put an absolute positioned image inside and then move an image left or right (or up and down) to view just 1 cell of the image strip.
So lets take a look at simple and useful example, a color chooser for a shirt in a shopping cart.
The CSS is pretty simple but it sets up everything that is happening. Since overflow is hidden on the .strip container what part of the image strip were showing is just a matter of setting a negative left value on the img.
And finishing things up here is the full image.
Were gaining 2 main benefits from using an image strip like this. First we make less requests to the server, and if the images in question is small were saving overall file size since there is less overhead. Most importantly in this example there is no image load flash and wait since all the images are already loaded.
Image Strips are a great trick to add to your AJAX toolbox, let me know when you find a place to use one.
I’d like to thank Josh Gomez for helping me the images used in this article.
Stand-alone example versions of the code on this post are available in this posts examples directory.
If you got a bunch of photos of the same size you can make the combined image strip using Image Magick’s montage command.
montage -geometry +0+0 -tile 10x1 photo-*.jpg complete.jpg
Breaking down the command, -geometry +0+0 tells montage to use no whitespace between the images, -tile 10x1 says to put all 10 images in a single row. photo-*.jpg is the input files and complete.jpg is the output file.