javascript - Run function after jquery append -
i have function inserting more image posts web page. after inserts images, div has image within of resizes same width image. issue having is running before images have loaded divs not beingness resized.
any ideas how can set run when images loaded?
function load_more(url, page, page_name) { $.ajax({ type: 'post', url: "/app/load_more/" + page_name + "/pagename/" + url, data: 'id=testdata', datatype: 'json', cache: false, success: function (data) { $(".next").remove(); $("#top").append(data['top']); $("#bottom").append(data['bottom']); $('.img-wrap').each(function () { if ($(this).find('img').attr('src') != "") { $(this).animate({ width: $(this).find('img').css("width") }, 300); } }); } }); }
you can utilize load
event on image wait them load:
$('.img-wrap').each(function() { var div = $(this); var img = div.find('img'); if (img.attr('src') != ""){ img.on('load', function(){ div.animate({ width: img.css("width") }, 300); }); } });
javascript jquery ajax dom
No comments:
Post a Comment