使用scrollreveal.js结合scrollreveal.css实现页面进入视口即播放动画

页面中引入scrollreveal、scrollreveal相关库

loadData: function (xmr) {
                this.mxmr=xmr;
                let data=[
                    {el: '.logo', duration: 1, animated: 'animate__fadeInDown', reset: true},
                    {el: '.book', duration: 1.4, animated: 'animate__fadeIn', reset: true},
                    {el: '.title', duration: 1.5, animated: 'animate__bounceIn', reset: true},
                    {el: '.time', duration: 2.5, animated: 'animate__fadeInRight', reset: true},
                    {el: '.desc', duration: 1.5, animated: 'animate__fadeInUp', reset: true},
                    {el: '.th', duration: 1.5, animated: 'animate__bounceIn', reset: true},
                    {el: '.people', duration: 1.8, animated: 'animate__fadeInLeft', reset: true},
                    {el: '.activeArea', duration: 1.5, animated: 'animate__fadeInUp', reset: true},

                ];


                this.commonAnim(data);
            },

            commonAnim:function (animList) {
                console.log("animList",animList);
                if(!animList) return;
                animList.map((data)=>{
                    this.scrollReveal.reveal(data.el,{
                        reset:data.reset,
                        mobile: true,
                        afterReset: function (el) { //离开视图时重置,移除动画类名
                            el.classList.remove('animate__animated');
                            el.classList.remove(data.animated);
                            //console.log("离开视窗");
                        },
                        beforeReveal: function (el) { // 到达视图时触发,增加动画类名,添加执行动画时常
                            //console.log("进入视窗");
                            el.classList.add('animate__animated');
                            el.classList.add(data.animated);
                            if (data.duration)
                                el.style['animation-duration'] = data.duration + 's';
                            el.style['-webkit-animation-duration'] = data.duration + 's';
                        }
                    })
                })

            },
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值