I'm trying to get an image to fade out on hover, swap the image src, then fade back in. I'm animating opacity as the fadein/out functions set the element to display:none and I don't want this to happen.
Here's my code:
$('.imgswap').on({
'mouseenter': function(){
var $nextimg = $(this).data('imagesource');
if ($nextimg != $('#floorplan').attr('src')) {
$('#floorplan').animate({"opacity": "0"}, "fast",function () {
$('#floorplan').attr('src',$nextimg).animate({"opacity": "1"}, "fast");
});
}
}
});
Can you see why the second animate function is not firing off AFTER setting the source?
UPDATE: After further testing, and trying one of the comments below, it turns out that the animate IS firing after the SRC has been set, but if the new image hasn't loaded in yet, the old image stays visible until the new one is available. So... I think I need some sort of 'loader' that only fires the animate({"opacity": "1"}, "fast")
when the new image has been loaded in.