0

Hi,

In one of my web page When user clicks a thumbnail view of my page then the main Image will show that corresponding

My code as followa

jQuery('products li img').click(function(){

var as=jQuery(this).attr('href');

jQuery('#mainImg').attr('src',as)
});


My doubt is at the time of user clicks on that thumb a small preload will need to show ... Please help

Thanks in advance
:)

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Airshow
0

This will preload all the images, so they will stand a reasonable chance of being in browser cache when user clicks each thumbnail:

...
  var img, mainImg = jQuery('#mainImg').get(0);
  jQuery('products li img').each(function(){//loop to preload images immediately
    img = new Image();
    img.src = this.href;
  }).click(function(){//establish onclick handler
    mainImg.src = this.href;
  });
...

untested

Make sure it's all wrapped in window.onload = function(){...}; or jQuery(document).ready(function(){...}); or similar.

Airshow

Edited by Airshow: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.