
轮播图循环时闪动的原因
在轮播图切换到最后一页时,如果用户切换速度较慢,会出现图片闪动的情况。这是因为使用translate3d移动元素时,当元素移动到页面边缘时,由于浏览器性能优化,会触发复合图层合成,从而导致画面闪烁。
解决方案
为了解决轮播循环时出现的闪动问题,可以采取以下措施:
优化changecur方法
重新编写changecur方法,在切换到第一页或最后一页时,先暂停元素过渡,然后立刻更新元素位置,最后恢复元素过渡。
使用transform直接实现轮播
可以使用transform属性直接实现轮播,避免使用translate3d导致的复合图层合成问题。
代码示例
changeCur(add){ this.con.style.transitionDuration = '.3s'; //切换cur方法 let cur = this.out.style.getPropertyValue('--cur'); cur = parseInt(cur); if(add){ 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{ 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); } }}
以上就是轮播图循环时出现闪动,如何解决?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1498097.html
微信扫一扫
支付宝扫一扫