轮播循环时图片闪动的根源
在轮播图中,当用户在最后一页切换回第一页时会出现图片闪动现象。这是因为在使用 translate3d 进行页面切换时,当即将切换回第一页时,页面会瞬间消失再出现,导致闪烁。
解决方案
针对此问题,可以对 JavaScript 代码进行调整,具体如下:
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);
}
}
}
以上就是轮播图最后一页切换回第一页时图片闪动怎么办?的详细内容,更多请关注知识资源分享宝库其它相关文章!
版权声明
本站内容来源于互联网搬运,
仅限用于小范围内传播学习,请在下载后24小时内删除,
如果有侵权内容、不妥之处,请第一时间联系我们删除。敬请谅解!
E-mail:dpw1001@163.com
发表评论