There and Back Again

jQuery Image Strip

Working for Obu Web i’ve found myself spending less time on code I would say meets the definition of AJAX I put in my book and more time on code that used to be called DHTML. But I guess I’m ok calling it AJAX, at least its pronouncable and building little JavaScript widgets is fun.

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.


So the HTML is pretty simple, we have a div with an image in it, and a dropdown that run a javascript function to move our position on the strip.

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.

The JavaScript is a small object, it provides 2 methods, currentCell and move. currentCell is used to ignore move requests to the same cell and move is the api you interact with. When you create a new ImageStrip you specify the container, the width of each cell and the animation speed in milliseconds. If the speed is set at 0, we immediatly move which is useful for tasks like color versions. If its a larger number like 800 we get a neat animation effect which was shown in the fancy example at the begining of this article.

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.

Unix Tip

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.

178 thoughts on “jQuery Image Strip

  1. Pingback: 240 plugins jquery | najmahilmi

  2. Pingback: JQuery: Пара сотен плагинов в одной заметке « abdurayimov.com

  3. Pingback: 32+ jquery image display plugin « ChipMint

  4. Pingback: 240多个jQuery插件 功能强大 齐全 | iXaml.net | WPF,Metro,Silverlight,Windows 8,WP知识站

  5. Pingback: 240多个jQuery插件 功能强大 齐全 | 乱炖

  6. Pingback: 240个jquery插件 | 网络钻头

  7. Pingback: 14 jQuery Plugins for Working with Images « Designers BLOG :: Updates, Resources, Tutorials for Designers:: HTML5, CSS3, HTML, CSS, JQUERY

  8. Pingback: 14 jQuery Plugins for Working with Images « Designers BLOG :: Updates, Resources, Tutorials for Designers:: HTML5, CSS3, HTML, CSS, JQUERY

  9. Pingback: jquery插件列表【荐】 | 5CM实验室-学习、分享、交流平台

  10. Pingback: The ultimate jQuery Plugin List | Kollermedia.at

  11. Pingback: Pawoot.com » เครื่องมือช่วยในการพัฒนาเว็บไซต์ สำหรับ developer

  12. Pingback: Projelerinizde gerekli olabilecek 240 adet jQuery eklenti | Sekizncihayat Blog | Freelance Yazılım Hizmetleri

  13. Pingback: 黑 白 世 界 » 240个jQuery实现AJAX插件

  14. Pingback: 240个jquery插件 | 极限手指

  15. Pingback: 好用的jQuery插件清单 | 东东东

  16. Pingback: 200多个jQuery插件 | 闹心 Naoxx 资源

  17. Pingback: icecut的技术乐园 » jquery 插件链接

  18. Pingback: takeHoのへなちょこ日記 - takeHoのへなちょこ日記 | takeHoのへなちょこ日記

  19. Pingback: 推荐:240多个jQuery插件 - 中文吧

  20. Pingback: 关于JQuery插件的资料 « HTML5吧

  21. Pingback: 240多个jQuery插件 | ek32.com

  22. Pingback: 240多个jquery插件,值得收藏! | 然然-php技术博客-专注php程序设计然然-php技术博客-专注php程序设计

  23. Pingback: 42+ jQuery Image Gallery Plugins | Barkamedia

  24. Pingback: jquery插件240个 | 林洪优的博博

  25. Pingback: 海量的jQuery插件帖,很经典 — 逆袭吧IT分享网

  26. Pingback: | SunnyV

  27. Pingback: JQuery 插件列表 | 忘情睡

  28. Pingback: 240个jQuery实现AJAX插件 | 随风的李