Jquery LazyLoad.js 窗口大小调整后加载问题

发布于 2024-10-26 02:36:13 字数 317 浏览 0 评论 0原文

我正在为我的网站运行 LazyLoad 脚本,但其中的一个小方面存在问题。

我在水平滚动(从左到右)上使用延迟加载,图像相当宽。该脚本运行完美,并在 200 像素(或任何默认值)内淡入。

但是我注意到,如果窗口打开到较小的尺寸,然后打开到整个窗口,则占位符“延迟加载”仅加载在较小的窗口尺寸期间“在视图中”的图像。一旦滚动条移动,它就会加载,但我很好奇是否有任何脚本可以添加“当窗口大小调整时,重新测量观看空间”

希望这是有道理的。我对 JavaScript 知之甚少,所以如果有人知道如何解决这个问题,请随时回复,就好像您正在与 5 岁的孩子交谈一样,并提供逐步说明:)

Im running the LazyLoad script for my website and having an issue with one small aspect of it.

Im using Lazy Load on a Horizontal scroll (left to right) with fairly wide images. The script works perfectly and fades in within 200px (or whatever the default is).

However I noticed if the window is opened to a smaller size, then opened to full window, the placeholder, Lazy Load has only the image loaded that was "In View" during the smaller window size. It loads once the scroll bar is moved, but Im curious if there's any scripting I could add along the lines 'When the window resizes, re-gauge the viewing space'

Hopefully this makes sense. I know very little about JavaScript so if anyone knows how to solve this feel free to respond as if you were talking to a 5 year old with step by step instructions :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各自安好 2024-11-02 02:36:13

找到这行代码(在lazyload.js中):

$(settings.container).bind("scroll",function(event){var counter=0;elements.each(function(){if($.abovethetop(this,settings)||$.leftofbegin(this,settings)){}else if(!$.belowthefold(this,settings)&&!$.rightoffold(this,settings)){$(this).trigger("appear");}else{if(counter++>settings.failurelimit){return false;}}});var temp=$.grep(elements,function(element){return!element.loaded;});elements=$(temp);});

并在其后添加:

$(window).bind("resize",function(event){$(settings.container).trigger('scroll');});

Find this line of code (inside lazyload.js):

$(settings.container).bind("scroll",function(event){var counter=0;elements.each(function(){if($.abovethetop(this,settings)||$.leftofbegin(this,settings)){}else if(!$.belowthefold(this,settings)&&!$.rightoffold(this,settings)){$(this).trigger("appear");}else{if(counter++>settings.failurelimit){return false;}}});var temp=$.grep(elements,function(element){return!element.loaded;});elements=$(temp);});

and add after that this:

$(window).bind("resize",function(event){$(settings.container).trigger('scroll');});
北城半夏 2024-11-02 02:36:13

将 failure_limit 设置为 10 会导致插件在找到首屏下的 10 个图像后停止搜索要加载的图像。如果您有一个时髦的布局,请将此数字设置为较高的值以解决您的问题,例如:

$('img').lazyload({effect:'fadeIn', failure_limit:40});

Setting failure_limit to 10 causes plugin to stop searching for images to load after finding 10 images below the fold. If you have a funky layout set this number to something high to solve your problem, an example:

$('img').lazyload({effect:'fadeIn', failure_limit:40});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文