轮播回退时闪动的解决办法
在轮播图中,使用translate3d来移动页面时,在最后一页切换到第一页面时,会发生闪动。这是因为在最后一页切换下一张时,使用了过渡动画,而在第一页切换上一张时没有使用。
为了解决这个问题,需要确保在所有切换操作中都使用过渡动画。以下是如何修改changecur方法以修复该问题的示例:
changeCur(add){ // this.out.style.setProperty('--trans', 'transform'); this.con.style.transitionDuration = '.3s'; //切换cur方法 let cur = this.out.style.getPropertyValue('--cur'); cur = parseInt(cur); if(add){ // this.setCur(cur+1); // if(cur > this.num-1){ // setTimeout(() => { // // cur = 1; // // this.out.style.setProperty('--trans', 'none'); // this.con.style.transitionDuration = '0s'; // this.setCur(1); // }, 300) // } if (cur === this.num) { this.con.style.transitionDuration = '0s'; this.setCur(0); this.con.offsetWidth; this.con.style.transitionDuration = '.3s'; this.setCur(1); } else { this.setCur(cur + 1); } } else{ // this.setCur(cur-1); // if(cur < 2){ // // setTimeout(() => { // // // cur = this.num; // // // this.out.style.setProperty('--trans', 'none'); // // this.con.style.transitionDuration = '0s'; // // this.setCur(this.num); // // }, 300) // } if (cur === 1) { this.con.style.transitionDuration = '0s'; this.setCur(this.num + 1); this.con.offsetWidth; this.con.style.transitionDuration = '.3s'; this.setCur(this.num); } else { this.setCur(cur - 1); } } }