How to lazy load images vertically & horizontally?

耗尽温柔 提交于 2019-12-06 15:20:06

Add this to also assign the lazyload to the images that are not in the #hcontainer

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

    $("img.lazy").lazyload({
        effect: "fadeIn",
        container: $("#hcontainer")
     });
});

Edit:

Demo

I would suggest, that you try lazySizes. The big difference to other lazyloaders is, that lazySizes automatically detects visibility changes without configuration.

This allows separation of concerns, because you don't need to touch your JS lazyloader configuration, in case you change your CSS and add a scroll container or add images inside a mega menu and such things.

Everything you need to do, is to add the lazysizes script and use data-src instead of src and add the class lazyload.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!