有时,在以freeMode设置为true的freeMode中滑动,滚动或拖动时,索引为1的幻灯片会居中

时间:2018-09-11 14:38:58

标签: swiper

我正在使用以下设置初始化刷卡器。我的要求是获取居中幻灯片的详细信息。但是有时候,即使我从幻灯片50滚动或滑动到其他位置,索引滚动为1的幻灯片也会自动居中。

{
speed: 800,
initialSlide: 0,
slidesPerView: 13,
spaceBetween:0,
centeredSlides: true,
slideToClickedSlide: true,
freeMode: true,
freeModeSticky: true }

以下是小提琴https://jsfiddle.net/auk4fiddle/drqLzb08/11/的链接

在swiper.js文件中进行调试后,我发现,对于freeModeSticky = true而言,slideToClosest()函数称为onTouchEnd(),该函数将返回默认值为1的slidesPerGroup变量。以下是if条件,即引起问题。

  function slideToClosest (speed, runCallbacks, internal) {
if ( speed === void 0 ) speed = this.params.speed;
if ( runCallbacks === void 0 ) runCallbacks = true;

var swiper = this;
var index = swiper.activeIndex;
var snapIndex = Math.floor(index / swiper.params.slidesPerGroup);

if (snapIndex < swiper.snapGrid.length - 1) {
  console.log("swiper.rtlTranslate:- "+swiper.rtlTranslate+" swiper.translate:- "+swiper.translate);
  var translate = swiper.rtlTranslate ? swiper.translate : -swiper.translate;

  var currentSnap = swiper.snapGrid[snapIndex];
  var nextSnap = swiper.snapGrid[snapIndex + 1];
  console.log("currentSnap:- "+currentSnap+" nextSnap:- "+nextSnap);
  console.log("lhs:- "+(translate - currentSnap)+" rhs:- "+(nextSnap - currentSnap) / 2);

  // Here is the condition that is returning the slidesPerGroup
    if ((translate - currentSnap) > (nextSnap - currentSnap) / 2) {
      index = swiper.params.slidesPerGroup;
    }
}

由于我没有使用变量slidesPerGroup,因此更改了if条件,如下所示:

 if (((translate - currentSnap) > (nextSnap - currentSnap) / 2) && swiper.params.slidesPerGroup != 1) {
      index = swiper.params.slidesPerGroup;
    }

Click this video link to see the issue I am facing.

Here is another video link to see the issue.

我尝试了配置变量的各种组合,但无法解决该问题。我想念什么吗?有人可以帮我解决这个问题吗?

0 个答案:

没有答案