简体   繁体   English

在页面加载时运行jquery延迟加载不滚动

[英]Run jquery lazy load on page load not scroll

I am trying to use the jQuery lazy load plugin with the jQuery Isotope plugin . 我试图使用jQuery延迟加载插件jQuery Isotope插件 Things seem to be playing together nicely, however, I am having a tough time figuring out how modify the lazy load plug in to my needs. 事情似乎很好地融合在一起,但是,我很难搞清楚如何根据我的需要修改延迟负载。

The plug in defaults to handling the scroll event to trigger lazy loading. 插件默认处理scroll事件以触发延迟加载。 There is also hover and click. 还有悬停和点击。 I would like the plugin to fire on page load. 我希望插件能够在页面加载时触发。 Say, 2000ms after $(window).load() has completed. 比如说, $(window).load()完成后的2000ms。

I see I can create my own event functions per the documentation like so: 我看到我可以根据文档创建自己的事件函数,如下所示:

$(function() {          
    $("img:below-the-fold").lazyload({
        event : "sporty"
    });
});
$(window).bind("load", function() { 
    var timeout = setTimeout(function() {$("img.lazy").trigger("sporty")}, 5000);
}); 

However, due to my ignorance, I cannot see how I would work with this snippet to create my own page load event. 但是,由于我的无知,我无法看到如何使用此代码段创建自己的页面加载事件。

I would like the initial images to lazy load after $(window).load() , then when I apply isotope filtering events, the new items to be lazy loaded as they populate the DOM. 我想在$(window).load()之后将初始图像延迟加载,然后当我应用同位素过滤事件时,新项目在填充DOM时将被延迟加载。

Any help is much appreciated. 任何帮助深表感谢。

I have made a lazy load plugin that might help. 我做了一个懒惰的加载插件,可能会有所帮助。 Once initialized you can just call $.fn.lazyloadanything('load') and it will auto load without having to scroll first. 初始化后,您只需调用$.fn.lazyloadanything('load') ,它将自动加载而无需先滚动。 No need to customize. 无需定制。 Check it out: 看看这个:

https://github.com/shrimpwagon/jquery-lazyloadanything https://github.com/shrimpwagon/jquery-lazyloadanything

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM