jQuery的lazyload与阿贾克斯 [英] Jquery lazyload with ajax

查看:142
本文介绍了jQuery的lazyload与阿贾克斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用lazyload()在我的电子商务网站。 lazyload()的伟大工程。我用这个code做到这一点:

I use lazyload() on my ecommerce website. lazyload() works great. I use this code to do that:

$(function(){
  $("img.lazy").lazyload({ 
  effect : "fadeIn"
          });
});

也有像彩色滤光片一些,价格等,这是运行Ajax和展示新的结果。当新的结果到来,lazyload()无法正常工作。我知道,我必须使用lazyload()现场(),委托()或()。但我对jQuery的一个新手,我不能这样做。任何人都可以帮助我吗?我的jQuery的版本是1.7.2,我们可以使用()。

Also there are some filter like color, price etc. which is run an ajax and show new result. When new result come, lazyload() doesn't work. I know that I have to use lazyload() with live(), delegate() or on(). But I am a newbie on jquery and I couldn't do that. Can anyone help me please? My jquery version is 1.7.2 and we can use on().

推荐答案

注:在此答案被接受的时候,这个工作。延迟加载插件改变,现在它被打破了。我不能unaccept答案我也不能删除。

还有一个Q&放大器; A即表明处理它作为AJAX请求负责插入额外的DOM的一部分:

There is another Q&A that suggests handling it as part of the AJAX request responsible for inserting the additional DOM:

<一个href="http://stackoverflow.com/questions/10035985/binding-image-lazy-loading-to-new-images-inserted-after-ajax-request">Binding图像延迟加载到Ajax请求后插入新的图像

不过,这是我会怎么做:

However, this is how I would do it:

$(document).on('DOMNodeInserted', 'img.lazy', function() {
    $(this).lazyload({
        effect: 'fadeIn'
    });
});

演示:的jsfiddle

这篇关于jQuery的lazyload与阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆