首页  >  问答  >  正文

javascript - CSS轮播切换动画

如图

用JS写的一个动画,设置了过度效果,就会出现这样的情况,这中情况JS怎么更改?

function moveSlide() {
  var slides = $('.slide');
  
  // for (var i = 0; i < slides.length; i++) {
    slides.forEach(function(item) {
      var leftValue = parseInt(item.style.left);

      if (leftValue == -100) {
        leftValue = 100;
        item.style.left = leftValue + '%';
      }else if(leftValue == 100 || leftValue == 0){
        leftValue -= 100;
        item.style.left = leftValue + '%';
      }
    }, this);
習慣沉默習慣沉默2685 天前831

全部回复(1)我来回复

  • 学习ing

    学习ing2017-06-12 09:35:00

    1.leftValue=0 >> leftValue -=100 >> leftValue=-100
    2.leftValue=-100 >> leftValue = 100
    3.leftValue=100 >> leftValue -=100 >> leftValue=-100
    你的leftValue就只有两个值在变化啊,你的判断写的不对。既然你用过渡动画建议使用animate();

    回复
    0
  • 取消回复