var sliderElement = document.querySelector(".project__slider");
var swiperSlider = {};
var sliderType = window.innerWidth < 857 ? "mobile" : "desktop";
function initSlider(type) {
var sliderSettings = {};
if (type === "mobile") {
sliderSettings = {
observer: true,
observeParents: true,
effect: "fade",
fadeEffect: {
crossFade: true,
},
autoplay: {
delay: 1000,
disableOnInteraction: false,
},
spaceBetween: 50,
speed: 800,
centeredSlides: true,
// описание настроек для мобильной вариации.
};
} else {
sliderSettings = {
observer: true,
observer: true,
observeParents: true,
slidesPerView: 1,
spaceBetween: 50,
speed: 800,
direction: "vertical",
centeredSlides: true,
pagination: {
el: ".swiper-pagination",
type: "bullets",
clickable: true,
},
// описание настроек для десктопной вариации.
};
} // конец if-else
// Проверяем, есть ли в объекте слайдера метод destroy, и если есть - вызываем его.
if (swiperSlider.destroy && typeof swiperSlider.destroy === "function") {
swiperSlider.destroy(); // Возможно,если в круглые скобки передать true то будет лучше.
}
swiperSlider = new Swiper(sliderElement, sliderSettings);
}
initSlider(sliderType);
window.addEventListener("resize", () => {
if (window.innerWidth < 857 && sliderType == "desktop") {
sliderType = "mobile";
initSlider(sliderType);
} else if (window.innerWidth >= 857 && sliderType == "mobile") {
sliderType = "desktop";
initSlider(sliderType);
}
});
let sliderAbout = document.querySelector(".project__slider");
let mySwiper;
function sl() {
if (window.innerWidth > 857) {
mySwiper = new Swiper(sliderAbout, {
observer: true,
observeParents: true,
slidesPerView: 1,
spaceBetween: 50,
speed: 800,
direction: "vertical",
centeredSlides: true,
pagination: {
el: ".swiper-pagination",
type: "bullets",
clickable: true,
},
});
}
if (window.innerWidth < 857) {
mySwiper.destroy();
sliderAbout.dataset.mobile = "false";
}
}
sl();
window.addEventListener("resize", () => {
sl();
});
var mySwiper2 = undefined;
function initSwiper() {
var screenWidth = $(window).width();
if(screenWidth < 857 && mySwiper2 == undefined) {
mySwiper2 = new Swiper('.project__slider_mob', {
observer: true,
observeParents: true,
effect: "fade",
fadeEffect: {
crossFade: true,
},
autoplay: {
delay: 1000,
disableOnInteraction: false,
},
spaceBetween: 50,
speed: 800,
});
} else if (screenWidth > 857 && mySwiper2 != undefined) {
mySwiper2.destroy();
mySwiper2 = undefined;
}
}
//Swiper plugin initialization
initSwiper();
//Swiper plugin initialization on window resize
$(window).on('resize', function(){
initSwiper();
});