轮播图轮回切换时的闪动问题
在使用 translate3d 来实现轮播图时,在最后一页切换到第一页时,如果您切换较慢,可能会出现图片闪动的问题。
这是因为在切换的时候,transition 的过渡时间还在继续,如果鼠标点击很快,图片会瞬间跳到下一张,不会等到过渡结束。因此,会出现图片闪动的情况。
解决方案
您可以修改 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 { // // // 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); } } }
登录后复制
以上就是使用 translate3d 实现轮播图时如何解决最后一页切换到第一页时的闪动问题?的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2799928.html