首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Swiper销毁()未开火

Swiper销毁()未开火
EN

Stack Overflow用户
提问于 2019-11-21 09:37:32
回答 1查看 4.3K关注 0票数 1

我正在尝试使用https://github.com/nolimits4web/swiper函数在其他任何东西上禁用Swiper ( destroy() ),但是我得到了错误Uncaught TypeError: swiper.destroy is not a function

我试过各种不同的东西,但我不能让它起作用。

代码语言:javascript
运行
复制
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;
EN

回答 1

Stack Overflow用户

发布于 2022-04-27 10:58:59

您是否尝试过MySwiper.destroy();而不是swiper.destroy();

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58971616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档