$(document).ready(function () { const swiper = new Swiper('.swiperMainTop', { slidesPerView: 1, spaceBetween: 0, direction: getDirection(), loop: true, autoplay: { delay: 3000, }, navigation: { nextEl: '.swiperMainTopNext', prevEl: '.swiperMainTopPrev', }, on: { resize: function () { swiper.changeDirection(getDirection()); }, }, }); function getDirection() { var windowWidth = window.innerWidth; var direction = window.innerWidth <= 0 ? 'vertical' : 'horizontal'; return direction; } });