【发布时间】:2011-05-29 02:37:51
【问题描述】:
基本上我在这里寻找的是性能。
$.post(link,
function(data){
//removes the image that was displayed while loading
$("#loadingImg").remove();
//append the new content, into the content div
//and add a div around the new content in order to lazy load
$("#content").append('<div id="new-page">' + data + '</div>');
//lazy load the images inside the new div
$("#new-page").find("img").lazyload({
placeholder : "/images/white.png", effect : "fadeIn" });
});
我想使用 jquery 插件 lazy load 来延迟加载附加到某些内容的图像。现在我可以看出,有和没有该代码的延迟加载行的加载时间完全相同(它加载了大约 20 张图像)。我现在假设 $("#content").append() 行在追加之前等待所有图像加载。
有没有办法将 html 放入页面中,停止浏览器加载该 html 中的图像,然后在用户滚动时加载它们?
顺便说一句,即使我这样做:
data = '<div id="new-page-' + pageCounter + '">' + data + '</div>';
var newData = $(data);
newData.find("img").lazyload({ placeholder : "/images/white.png", effect : "fadeIn" });
$("#content").append(newData);
加载时间仍然相同...
感谢您的帮助!
【问题讨论】:
标签: jquery ajax performance lazy-loading