我正在使用 .append() 将图像加载到 div
如何在这些新添加的图像上使用惰性加载器插件?有没有办法做到这一点?
更新: 这是代码
//This is a live search script, type something in #livesearch input and it populates a #results ul list with the results
$('#livesearch').live('keyup', function(event) {
//after ke press detected immediately clear the results div of any previous content
$('#results').html("");
// Use the inputed letters to send off an ajax request
$.getJSON("http://xxxxxx.com/live/" + $(this).val(), function(resp){
//the ajax returns a json object, next loop through the object and print out the results in a list using append
$.each(resp.response.docs, function(index, item) {
$('#results').append("<li><div style='background-color:rgb(31,31,31);padding:15px;color:rgb(255,255,255);'><span class='inline' style='width:125px;height:50px;margin-right:15px'><img data-original='img/"+item.nameid+".png' src='img/grey.gif' class='lazy' style='display:inline' height='50px'></span><span class='inline' style='width:300px;'><div style='font-size:14px;'>"+item.name+"</div><div style='font-size:12px;color:rgb(99,99,99)'>Strategy | 4 months ago | Played 2,000 times</div></span></div></li>");
});
});
// The list that was created includes images and could have several hundred of them, therefore I would like to lazy load them as you scroll down
// This line of code is just one of my failed attempts
$("img.lazy").lazyload();
});
因为图像是在文档加载后添加的,所以我认为惰性加载器插件很难“看到”原始 HTML 中的图像,因为它们不存在。也许 LazyLoad 不能做我想做的事。