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對應(yīng)屏幕出現(xiàn)前三個項
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'; //設(shè)置過渡
oUl.style.transform='translateX('+(-425)*index+'px)'; //移動到index==3
timer=setInterval(move,2000); //開啟定時器
}
走同樣的路,發(fā)現(xiàn)不同的人生
Isn’t the initial value 0? After you click, it will jump to 4
oUl.style.transform='translateX('+(-425)*index+'px)';