JS / GSAP自定义轮播轮换错误

时间:2019-03-14 16:10:59

标签: javascript html css carousel gsap

我创建了一个自定义旋转木马,该旋转木马可以完美地前进,而向后完美地前进,除非您快速单击左箭头(在滑块完全旋转之前)。然后,顺序保持正确,但是看起来图像是从右侧而不是左侧发出的。我的previousPolaroid()函数中没有任何内容告诉旋转木马从右向左移动东西,我很茫然。任何帮助将不胜感激!

https://codepen.io/ccogswell/pen/Ygrzrv

function previousPolaroid() {
    TweenMax.to($polaroidSlide.eq(currentSlide), 1, {left:"60%", opacity:0.5, scale:0.5});
    var prevSlide = currentSlide;
    if (currentSlide > 0) {
      currentSlide--;
    }
    else {
      currentSlide = $polaroidSlide.length - 1;
    };
    if (currentSlide > 0) {
      var followingSlide = currentSlide - 1;
    }
    else {
      followingSlide = $polaroidSlide.length - 1;
    }


    if ($polaroidSlide.length > 3) {
        if (currentSlide == 0) {
            var left = $polaroidSlide.length - 1;
        }
        else {
            left = currentSlide - 1;
        }
        if (currentSlide == $polaroidSlide.length - 1) {
            var right = 0;
        }
        else {
            right = currentSlide + 1;
        }
        var range = [];
        for (i = 0; i < $polaroidSlide.length; i++) {
            range.push(i);
        }

        for (i = 0; i < range.length; i++) {
            if ((range[i] != left) && (range[i] != right) && (range[i] != currentSlide)) {
                TweenMax.set($polaroidSlide[i], {opacity:0, scale:0});
            }
        }
    }

    TweenMax.fromTo($polaroidSlide.eq(followingSlide),1, {left:"-100%", opacity:0,scale:0}, {left:"-60%", opacity:0.5,scale:0.5});
    TweenMax.fromTo($polaroidSlide.eq(currentSlide), 1, {left: "-60%", opacity:0.5, scale:0.5}, {left:"0px", opacity:1, scale:1});
  }

0 个答案:

没有答案