Hope you can advise I would like to add some simple fade in out of an image replacement which I have hooked into a select menu.ie,
$("#vehicle").change(function(){
var selected = $(this).val();
$("#selectedVehicle").attr('src', '/assets/images/mini/'+selected+'.png');
});
<img id="selectedVehicle" src="/assets/v2/images/select-vehicle.png">
any suggestions how I can do it?
This will work best if you preload the images.
This will fade the image out, change the
src
, then fade it back in. Reference the jQuery docs for more information on the fading functions.Again, you should preload your images, otherwise it might fade back while still loading.
I've gone for preloading the image on page load, rather than on the fly...:
Example with "load" event: