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);
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();