Skip to content
Advertisement

OnClick thumbnails – load image

I have a simple image gallery of about 25-30 photos with a thumbnails strip What i want is to load only the image that i click the thumbnail for not to wait until all the 25-30 photos are loaded because it slows down my website. Any ideas how to do that?

Advertisement

Answer

First, put all 25-30 photos on the page in a way that won’t load them; the simplest way is to give them a CSS style of display:none. Then, put all your thumbnails on the page, and add jQuery logic like: $('.thumbnail').on('click', function() {.... The click handling function can then use jQuery’s show to show the full images as appropriate.

In other words, something like:

(HTML)

JavaScript

(JS)

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement