Jquery lazyload with ajax

后端 未结 8 1488
-上瘾入骨i
-上瘾入骨i 2021-01-17 23:26

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

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


        
8条回答
  •  情话喂你
    2021-01-18 00:09

    NOTE: At the time this answer was accepted, this worked. The lazy loading plugin changed and now it is broken. I cannot unaccept the answer nor can I delete it.

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

    Binding image lazy loading to new images inserted after ajax request

    However, this is how I would do it:

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

    Demo: jsfiddle

提交回复
热议问题