[英]Slick-Carousel autoplay starting when element in view
I use the autoplay function in slick slider to change the slides every 10 seconds:我在光滑的 slider 中使用自动播放 function 每 10 秒更换一次幻灯片:
jQuery(window).on('load resize', function () {
jQuery('.slider').not('.slick-initialized').slick({
arrows: false,
dots: true,
autoplay: true,
autoplaySpeed: 10000,
speed: 1500
});
});
The autoplaySpeed function starts counting when the page is loaded but i want to start the count just when the slick-element comes into view. autoplaySpeed function 在页面加载时开始计数,但我想在 slick-element 进入视图时开始计数。 How is it possible to load the slider on page load but start autoplay when the element arrives in the viewport?如何在页面加载时加载 slider 但在元素到达视口时开始自动播放?
You can set autoplay: false
when you initialize your slideshow and then when the slideshow enters the viewport, you can set the option to true
.您可以在初始化幻灯片时设置autoplay: false
,然后当幻灯片进入视口时,您可以将选项设置为true
。
$('.slider').slick('slickSetOption', 'autoplay', true);
To detect when the element comes into view, see: How can I tell if a DOM element is visible in the current viewport?要检测元素何时进入视图,请参阅: How can I tell if a DOM element is visible in the current viewport?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.