javascript - Swiper JS destroy()不触发
问题描述
我正在尝试使用该功能在移动设备以外的任何设备上禁用 Swiper JS ( https://github.com/nolimits4web/swiperdestroy()
) ,但出现错误Uncaught TypeError: swiper.destroy is not a function
。
我尝试了各种不同的东西,但我无法让它工作。
import Swiper from 'swiper';
const ImageCarousel = $el => {
let swiper = Swiper;
let init = false;
function swiperMode() {
let mobile = window.matchMedia('(min-width: 0px) and (max-width: 768px)');
let tablet = window.matchMedia('(min-width: 769px) and (max-width: 1024px)');
let desktop = window.matchMedia('(min-width: 1025px)');
// Enable (for mobile)
if (mobile.matches) {
if (!init) {
init = true;
const MySwiper = new Swiper('.swiper-container-cta', {
direction: 'horizontal',
loop: false,
speed: 1000,
grabCursor: true,
watchSlidesProgress: false,
mousewheelControl: true,
keyboardControl: true,
width: 280,
spaceBetween: 16,
});
}
}
// Disable (for tablet)
else if (tablet.matches) {
swiper.destroy();
init = false;
}
// Disable (for desktop)
else if (desktop.matches) {
swiper.destroy();
init = false;
}
}
// console.log(swiper);
window.addEventListener('load', () => {
swiperMode();
});
window.addEventListener('resize', () => {
swiperMode();
});
};
export default ImageCarousel;
解决方案
推荐阅读
- sql - SQL:如何生成不存在的组合
- c - C 中的指针和数组。这个概念不是很受欢迎。
- google-cloud-platform - GCMLE NotFoundError:libnccl.so.2:无法打开共享对象文件
- c# - 在 asp.net core 2.1 上使用 Hangfire 发送电子邮件
- linux - 创建包含特定文本的文件 zip
- sql - 显示带有硬编码日期的日期
- sql - SQL 'FROM UNNEST' 的语义是什么?
- bash - Bash for 循环显示不需要的文件/目录
- php - php 连接到 mysql 不起作用(树莓派 3 / apache2)
- regex - 如何从 Typescript 中的正则表达式 exec 匹配访问组?