I have this code by which I am changing main image on click of thumbnails
$(".thumb").click(function() {
$("#mainimage").attr("src", $(this).attr("alt"));
});
I want to show wait gif while the news image loads. thanks
I have this code by which I am changing main image on click of thumbnails
$(".thumb").click(function() {
$("#mainimage").attr("src", $(this).attr("alt"));
});
I want to show wait gif while the news image loads. thanks
Use .load. This event is fired when the image has finished loading, you could hide your loading gif in this event handler
$("#mainimage").load(function(){
//Hide your wait gif
});
Show your loading gif before setting the src
$(".thumb").click(function() {
//show your wait gif
$("#mainimage").attr("src", $(this).attr("alt"));
});
Update: This would not work if the image is cached and the event won't trigger.
Can cease to fire for images that already live in the browser's cache
A simple workaround is appending a random string to prevent caching
$(".thumb").click(function() {
//show your wait gif
$("#mainimage").attr("src", $(this).attr("alt") + "?" + Math.random());
});
This may have performance hit, but it works