Swiper:将自定义幻灯片设置为活动

发布于 2025-02-08 09:01:15 字数 854 浏览 3 评论 0原文

我正在使用 swiper 显示一年中每个月的滑块。 它从左向右滑动。

我现在想从左侧的本月开始。 如果之前有一个月,则应该在左侧偏移量。

我试图给出.swiper-slide类活动类.swiper-slide-active

<div class="swiper-slide swiper-slide-active">

但这不起作用。

在文档中,我没有发现在设置中设置一个Acive幻灯片的参数。 有什么办法做到这一点吗?

这是我当前的代码: https://codepen.io/cray_io/cray_code/pen/pen/ Dydrlbp

var swiper = new Swiper(".swiper-months", {
    cssMode: false,
    slidesPerView: 3.5,
    spaceBetween: 16,
    activeIndex: 6,
    mousewheel: {
        forceToAxis: true,
    },
});

ActiveIndex:6也无法正常工作。我不确定这是正确的。

I'm using Swiper to show a slider with every month of the year.
It slides from left to right.

I now want to start with the current month on the left side.
If there are month before, they should be in the left offset.

I tried to give the .swiper-slide class the active class .swiper-slide-active:

<div class="swiper-slide swiper-slide-active">

But that doesnt work.

In the docs I found no parameter to set a acive slide in the settings.
Is there any way to do this?

Here's my current code: https://codepen.io/cray_code/pen/dydrLBP

var swiper = new Swiper(".swiper-months", {
    cssMode: false,
    slidesPerView: 3.5,
    spaceBetween: 16,
    activeIndex: 6,
    mousewheel: {
        forceToAxis: true,
    },
});

The activeIndex: 6 doesn't work either. I'm not sure if that's correct.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澉约 2025-02-15 09:01:15

尝试primonslideActiveIndex仅用于获取实际的活动索引。但是我认为您shoud使用5 6开始在第六个月开始,因为第一个月以1开始,索引从0开始。

var swiper = new Swiper(".swiper-months", {
    initialSlide: 6,
    cssMode: false,
    slidesPerView: 3.5,
    spaceBetween: 16,
    mousewheel: {
        forceToAxis: true,
    },
});

Try initialSlide, activeIndex is just for getting the actual active index. But I think you shoud use 5 insted of 6 to start on sixth month, because first month starts with 1 and indexing starts from 0.

var swiper = new Swiper(".swiper-months", {
    initialSlide: 6,
    cssMode: false,
    slidesPerView: 3.5,
    spaceBetween: 16,
    mousewheel: {
        forceToAxis: true,
    },
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文