Skip to content

Commit 91de48b

Browse files
committed
Pause Swiper autoplay
1 parent 08410d0 commit 91de48b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ By default, the library applies the following optimisations to the scenarios to
3232
- Avoid asynchronous image decoding
3333
- Force Drupal.blazy to load all images
3434
- Pause the Slick slider autoplay
35+
- Pause the Swiper slider autoplay
3536
- Force oembed-lazyload videos to not load
3637
- Wait for fonts to load
3738
- Wait for the page to load completely

addons/setup.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ module.exports = async (page, scenario, config) => {
7171
iframe.loading = 'eager';
7272
});
7373

74+
// Avoid Slick carousel autoplay.
7475
if (typeof $ == 'undefined' && typeof jQuery == 'function') {
7576
window.$ = jQuery;
7677
}
@@ -93,6 +94,7 @@ module.exports = async (page, scenario, config) => {
9394
$(carousel).slick('slickGoTo', 0, true);
9495
}
9596
});
97+
// Improve text rendering for Slick carousels.
9698
if (slickCarousels.length > 0) {
9799
const head = document.head || document.getElementsByTagName('head')[0];
98100
const style = document.createElement('style');
@@ -103,6 +105,15 @@ module.exports = async (page, scenario, config) => {
103105
style.appendChild(document.createTextNode(css));
104106
}
105107

108+
// Avoid Swiper autoplay.
109+
const swiperCarousels = document.querySelectorAll('.swiper-initialized');
110+
swiperCarousels.forEach((carousel) => {
111+
if (carousel.swiper) {
112+
carousel.swiper.autoplay.stop();
113+
carousel.swiper.slideTo(0, 0);
114+
}
115+
});
116+
106117
// Force oembed-lazyload videos to not load when using intersection observer strategy.
107118
const oembedLazyVideos = document.querySelectorAll('.oembed-lazyload[data-strategy= "intersection-observer"]');
108119
oembedLazyVideos.forEach((video) => {

0 commit comments

Comments
 (0)