Home  >  Q&A  >  body text

javascript - Jump problem in carousel chart

There are four carousel items in total, and three can appear on the screen. I placed two copies side by side in the html to implement wireless carousel. However, when the position is at the starting point, clicking the forward button will cause a jump process. But when I execute it step by step in Chrome debugging, it doesn't jump. What's going on? The js code is as follows

pre.onclick=function(){              //pre为前移按钮
        if(index==0){                 //index==0对应屏幕出现前三个项
            index=4;
            oUl.style.transition='none';           //将css中的transition消除
            oUl.style.transform='translateX('+(-425)*index+'px)';   //移动到index==4
        }
        index--;
        clearInterval(timer);        //清除定时器
        oUl.style.transition='all 1s';    //设置过渡
        oUl.style.transform='translateX('+(-425)*index+'px)';   //移动到index==3
        timer=setInterval(move,2000);     //开启定时器
    }
怪我咯怪我咯2685 days ago387

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-19 10:36:28

    Isn’t the initial value 0? After you click, it will jump to 4

    oUl.style.transform='translateX('+(-425)*index+'px)';

    reply
    0
  • Cancelreply