Gif 加载图像 Owl Carousel LazyLoad in owl-lazy class?

Gif loading image Owl Carousel LazyLoad in owl-lazy class?

我想在 owl carousel2 中设置预加载器图像。我已经阅读了文档,但我没有找到任何在 lazyload 插件选项中使用预加载器图像的信息。

这里是插件网站:

https://owlcarousel2.github.io/OwlCarousel2/

我的代码:


<div class="single-product owl-carousel owl-theme">
  <a href="https://source.unsplash.com/0utRJ1mZoZg/1080x1350" data-fancybox="images">
    <img data-src="https://source.unsplash.com/0utRJ1mZoZg/600x600" class="img-fluid owl-lazy" />
  </a>

  <a href="https://source.unsplash.com/aiNU4cA4UzQ/1080x1350" data-fancybox="images">
    <img data-src="https://source.unsplash.com/aiNU4cA4UzQ/600x600" class="img-fluid owl-lazy" />
  </a>

  <a href="https://source.unsplash.com/295NLwGdrKM/1080x1350" data-fancybox="images">
    <img data-src="https://source.unsplash.com/295NLwGdrKM/600x600" class="img-fluid owl-lazy" />
  </a>

  <a href="https://source.unsplash.com/NzsTFFB6Ng8/1080x1350" data-fancybox="images">
    <img data-src="https://source.unsplash.com/NzsTFFB6Ng8/600x600" class="img-fluid owl-lazy" />
  </a>
</div>
$('.single-product').owlCarousel({
 loop : true,
 items : 1,
 nav : false,
 lazyLoad: true,
});

我需要提供预加载器 gif 图片,以获得更好的用户体验。

你能帮帮我吗? 非常感谢

您可以设置加载程序 gif 的背景图像。此外,我将 OwlCarousel 调用包装在 $(window).load() 中,这样它会在启动之前等待图像加载,而加载程序将处理任何无样式内容的 Flash (FOUC)

$(window).load(function() {
  $('.single-product').owlCarousel({
    autoHeight: true,
    lazyLoad: true,
    items: 1,
    autoplay: true,
    nav: false,
    dots: true,
    loop: true,
  });
});
.owl-carousel {
  height: 300px;
}

.owl-carousel {
  background: url("https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/ajax-loader.gif") no-repeat center center;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.min.css">

<div class="single-product owl-carousel owl-theme">
  <a href="https://source.unsplash.com/0utRJ1mZoZg/1080x1350" data-fancybox="images">
    <img data-src="https://source.unsplash.com/0utRJ1mZoZg/600x600" class="img-fluid owl-lazy" />
  </a>

  <a href="https://source.unsplash.com/aiNU4cA4UzQ/1080x1350" data-fancybox="images">
    <img data-src="https://source.unsplash.com/aiNU4cA4UzQ/600x600" class="img-fluid owl-lazy" />
  </a>

  <a href="https://source.unsplash.com/295NLwGdrKM/1080x1350" data-fancybox="images">
    <img data-src="https://source.unsplash.com/295NLwGdrKM/600x600" class="img-fluid owl-lazy" />
  </a>

  <a href="https://source.unsplash.com/NzsTFFB6Ng8/1080x1350" data-fancybox="images">
    <img data-src="https://source.unsplash.com/NzsTFFB6Ng8/600x600" class="img-fluid owl-lazy" />
  </a>
</div>

<script src="https://code.jquery.com/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>