search

Home  >  Q&A  >  body text

CSS carousel switching animation - Stack Overflow

As shown in the picture

When an animation written in JS is set with an excessive effect, such a situation will occur. How can JS change this situation?

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);
習慣沉默習慣沉默2756 days ago898

reply all(1)I'll reply

  • 学习ing

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

    1.leftValue=0 >> leftValue -=100 >> leftValue=-100
    2.leftValue=-100 >> ; leftValue -=100 >> leftValue=-100
    Only two values ​​of your leftValue are changing. Your judgment is wrong. Since you are using transition animation, it is recommended to use animate();

    reply
    0
  • Cancelreply