首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >防止单击事件时滑动滑块移动

防止单击事件时滑动滑块移动
EN

Stack Overflow用户
提问于 2021-10-20 09:53:21
回答 1查看 617关注 0票数 1

我使用的是Swiper JS (https://swiperjs.com/vue)。每个滑动幻灯片都包含一个按钮。在幻灯片或按钮上单击时,幻灯片将变为活动幻灯片,从而导致滑块移动。

单击非活动幻灯片的按钮时,是否可以防止滑块移动?

我曾尝试将preventClicks设置为true,但不幸的是它不起作用。

可以通过单击非活动幻灯片复制到此处(https://swiperjs.com/demos/110-slides-per-view/core.html)。我注意到一些点击并不会移动滑块,而另一些则会。

代码语言:javascript
代码运行次数:0
运行
复制
<swiper :modules="modules"
            :scrollbar="{ draggable: true }"
            :navigation="{prevEl: '#prev-slide', nextEl: '#next-slide', disabledClass: 'opacity-50 pointer-events-none'}"
            :breakpoints="options.breakpoints"
    >
        <swiper-slide v-for="plan in plans" :key="plan.id">
            <plan :plan="plan" @set-plan="setPlan"/>
        </swiper-slide>

        <div class="flex justify-center mt-2 space-x-2 py-3">
            <button type="button"
                    id="prev-slide"
                    class="inline-flex items-center px-2.5 py-1.5 border border-gray-300 shadow-sm text-xs font-medium rounded text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500">
                <arrow-narrow-left-icon class="h-5 w-5"/>
            </button>
            <button type="button"
                    id="next-slide"
                    class="inline-flex items-center px-2.5 py-1.5 border border-gray-300 shadow-sm text-xs font-medium rounded text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500">
                <arrow-narrow-right-icon class="h-5 w-5"/>
            </button>
        </div>
    </swiper>
EN

回答 1

Stack Overflow用户

发布于 2021-10-20 10:26:11

可以使用值为button的prop noSwipingSelector来实现所需的功能。单击非活动幻灯片的按钮时,它不再滑动到活动幻灯片。

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

https://stackoverflow.com/questions/69643852

复制
相关文章

相似问题

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