I added a swiper slider to a woocommerce site. The slider doesn't always work on variable items, most of the times it just shows a list of images.
The reason could be that the page doesn't fully renders until I'm initializing the slider. I've tried initializing the slider inside $(window).on('load', function(){})
but it didn't help.
Any suggestions ?
Variable item: https://escooter-shop.at/shop/e-scooter/e-scooter-easy-rider/
Simple item (works well): https://escooter-shop.at/shop/e-scooter/e-scooter-inmotion-l6/
The code:
$(window).on('load', function(){
console.log('Window on.load reached')
$('.single-product .thumbnails a').wrap('<div class="swiper-slide" />');
$('.swiper-slide').wrapAll( '<div class="swiper-wrapper"></div>');
$('.swiper-wrapper').wrapAll( '<div class="swiper-container"></div>');
$('<div class="swiper-button-prev"></div>').insertAfter( $('.swiper-wrapper'));
$('<div class="swiper-button-next"></div>').insertAfter( $('.swiper-button-prev'));
var mySwiper = new Swiper ('.swiper-container', {
direction: 'horizontal',
loop: true,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
slidesPerView: 3,
spaceBetween: 40,
breakpoints: {
480: {
slidesPerView: 2
},
}
});
});