简体   繁体   English

Zurb Foundation Orbit:延迟加载?

[英]Zurb Foundation Orbit: lazy-loading?

I'm very happy with orbit , the image slider of foundation , but it doesn't support lazy-loading out of the box.我对基础的图像滑块轨道非常满意,但它不支持开箱即用的延迟加载 I know Interchange , but that's not what I'm looking for.我知道Interchange ,但这不是我要找的。

I found this discussion with a fork as a solution.我用叉子找到了这个讨论作为解决方案。 I'd like to avoid a fork and prefer to extend the code, to keep my files upgradeable .我想避免分叉并更喜欢扩展代码,以保持我的文件可升级

There's no event like on('before-init.fndtn.orbit') .没有像on('before-init.fndtn.orbit')这样的事件

Does anyone know, how to fix this issue?有谁知道,如何解决这个问题?

Thanks in advance!提前致谢!

I switched to slick , because there was no proper way to use orbit with lazy loading out of the box, the time i asked this question.我切换到slick ,因为在我问这个问题的时候,没有正确的方法来使用带有开箱即用延迟加载的轨道。

A few months later I'm still happy with slick.几个月后,我仍然对 slick 感到满意。

<img data-lazy="img/lazyfonz1.png"/>

$('.lazy').slick({
  lazyLoad: 'ondemand',
  slidesToShow: 3,
  slidesToScroll: 1
});

It probably depends on your exact use case, but I was able to do it like this:这可能取决于您的确切用例,但我能够这样做:

  • In your template remove data-orbit from the orbit container, to prevent it from auto-initializing: <div class="orbit" role="region" aria-label="my gallery">在您的模板中,从轨道容器中删除data-orbit ,以防止它自动初始化: <div class="orbit" role="region" aria-label="my gallery">
  • Use jQuery.lazy() or a similar library to lazy load the images.使用jQuery.lazy()或类似的库来延迟加载图像。 I used data-src : <img class="orbit-image" data-src="/path/to/image.jpg" alt="description">我使用了data-src<img class="orbit-image" data-src="/path/to/image.jpg" alt="description">
  • When the images are lazy loaded (eg in a callback), re-add the data-orbit attribute, and re-initialize foundation for the orbit container.当图像被延迟加载时(例如在回调中),重新添加data-orbit属性,并重新初始化轨道容器的基础。 $gallery.find('.orbit').attr('data-orbit', '').foundation();

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

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