登录
首页 >  文章 >  前端

使用 translate3d 实现轮播图时如何解决最后一页切换到第一页时的闪动问题?

时间:2024-11-14 10:42:58 224浏览 收藏

从现在开始,努力学习吧!本文《使用 translate3d 实现轮播图时如何解决最后一页切换到第一页时的闪动问题? 》主要讲解了等等相关知识点,我会在golang学习网中持续更新相关的系列文章,欢迎大家关注并积极留言建议。下面就先一起来看一下本篇正文内容吧,希望能帮到你!

使用 translate3d 实现轮播图时如何解决最后一页切换到第一页时的闪动问题?

轮播图轮回切换时的闪动问题

在使用 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 < 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);
                    }

                }
            }

今天关于《使用 translate3d 实现轮播图时如何解决最后一页切换到第一页时的闪动问题? 》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

相关阅读
更多>
最新阅读
更多>
课程推荐
更多>