我想在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图像,以获得更好的UX。
能帮我吗? 非常感谢
答案 0 :(得分:0)
您可以设置加载程序gif的背景图像。另外,我将OwlCarousel调用包装在$(window).load()
内,以便它在启动图像之前等待图像加载,而加载器将处理任何无样式内容(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>