【问题标题】:Swiper Js - Only start slider when the device width is less than or equal to 515Swiper Js - 仅当设备宽度小于或等于 515 时才启动滑块
【发布时间】:2020-11-24 05:28:27
【问题描述】:

我正在使用这个滑块:https://swiperjs.com/api/

现在,我想在设备宽度等于或小于 515 时启动滑块。为此,我正在使用此 JS 代码,但当设备大于 515 时它不会停止滑块。它应该启动设备宽度小于等于515时的滑块:

var mySwiper = new Swiper('.swiper-container', {
    direction: 'horizontal',
    slidesPerView: 1,
    loop: true,
    pagination: {
        el: '.swiper-pagination',
        clickable: true,
    },
    autoplay: {
        delay: 3000,
    },
    breakpoints: {
        // when window width is >= 320px
        515: {
            slidesPerView: 1,
            spaceBetween: 20
        },
    }
});

【问题讨论】:

    标签: javascript swiper swiperjs


    【解决方案1】:

    对于小于或等于,如果我正确,我认为你这样做

    我已经有一段时间没有使用 java 脚本了

    【讨论】:

    • 我已经在条件之间使用了该代码,但仍然无法正常工作。喜欢var width = (window.innerWidth > 0) ? window.innerWidth : screen.width; if (width < 515) { ..... }
    猜你喜欢
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    相关资源
    最近更新 更多