javascript - Ajax wait till big image is loaded -
i need load big imges step step using ajax. want fade out last image when next image loaded.
i have checked several solutions in actual browsers nothing seems work.
so have now:
<div id="imgtoshow"> <img class="imgzoomclass" src="firstimage.jpg">
this ajax function loads onclick actual image (path) , next image path:
$.ajax({ type: "post", url: "../ajax/getimages", cache: true, data: "instance_id=" + $("#instance_id").val() + "&daterange=" + activerange + "&index=" + slideindex + "&direction=next&resolution=" + $("#resolution").val(), success: function(json){ var data = jquery.parsejson(json); if(data){ $("#imgtoshow").append('<img id="imgzoom" class="imgzoomclass" data-index="'+data.index+'" data-time="'+data.time+'" data-date="'+data.date+'" src="'+data.path+'">'); $(".imgzoomclass:first").remove().fadeout(); } } });
this loads next image path, append #imgtoshow , remove old image flickering in browser because old image removed before or meanwhile next image loading.
for grateful
before loading have hide image,you need give fade in effect after load image
<div id="imgtoshow"> <img class="imgzoomclass" src="firstimage.jpg" onload="fadein(this)" /> </div // fade in effect function window.fadein = function(obj) { $(obj).fadein(1000, function(){ $("#imgtoshow").find(".imgzoomclass").not($(obj)).remove(); }); } $.ajax({ type: "post", url: "../ajax/getimages", cache: true, data: "instance_id=" + $("#instance_id").val() + "&daterange=" + activerange + "&index=" + slideindex + "&direction=next&resolution=" + $("#resolution").val(), success: function(json){ var data = jquery.parsejson(json); if(data){ $("#imgtoshow").append('<img id="imgzoom" onload="fadein(this)" style="display:none;" class="imgzoomclass" data-index="'+data.index+'" data-time="'+data.time+'" data-date="'+data.date+'" src="'+data.path+'">'); } } });
in css
#imgtoshow { position: relative; width: 400px; // set custom width need height: 400px; // set custom height need border: 3px solid #000; } #imgtoshow .imgzoomclass { position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px; }
for more detail can check fiddle https://jsfiddle.net/rm1sxo3u/
Comments
Post a Comment