dkern / jquery.lazy

A lightweight, fast, feature-rich, powerful and highly configurable delayed content, image and background lazy loading plugin for jQuery & Zepto.
http://jquery.eisbehr.de/lazy
Other
1.02k stars 237 forks source link

Can I use jquery load() to load my images? #243

Closed PeterKarsson closed 3 years ago

PeterKarsson commented 3 years ago

First of all, thanks for a wonderful plugin. I am trying this code but jquery.laze will not be loaded. What am I doing wrong?

$("#id").load("load_100_images.php", function() { $('.lazy').lazy({ effect: "fadeIn", effectTime: 2000, threshold: 0 }); });

dkern commented 3 years ago

By default lazy wait for load of the browser. You use your own event, so I think you just need the bind config parameter:

$("#id").load("load_100_images.php", function() {
    $('.lazy').lazy({ effect: "fadeIn", effectTime: 2000, threshold: 0, bind: 'event' });
});

And maybe limit your new Lazy instance to the elements you just have loaded:

$("#id").load("load_100_images.php", function() {
    $('#id .lazy').lazy({ effect: "fadeIn", effectTime: 2000, threshold: 0, bind: 'event' });
});
PeterKarsson commented 3 years ago

By default lazy wait for load of the browser. You use your own event, so I think you just need the bind config parameter:

$("#id").load("load_100_images.php", function() {
    $('.lazy').lazy({ effect: "fadeIn", effectTime: 2000, threshold: 0, bind: 'event' });
});

And maybe limit your new Lazy instance to the elements you just have loaded:

$("#id").load("load_100_images.php", function() {
    $('#id .lazy').lazy({ effect: "fadeIn", effectTime: 2000, threshold: 0, bind: 'event' });
});

Thanks a lot. You made my day.