在vue中使用 animate.css 和 wowjs 注意事项

一、下载依赖

1、安装wowjs 和 animate.css

npm install wowjs -S
npm install animate.css -S

2、main.js 引用


import animated  from 'animate.css'
import wow from 'wowjs'

Vue.use(animated)
Vue.prototype.$wow = wow

3、使用页面 .vue 中 添加类名和 mounted 写入方法

//注意:
// 1、animate.css版本4用wow animate__animated animate__slideInUp类
//eg:
// <div class="wow animate__animated animate__slideInUp animate__delay-1s"></div>
// 2、animate.css版本3用wow slideInUp类
//eg:
//<div class="wow slideInUp"></div>



<template>
<div class="wow animate__animated animate__fadeInDown notice_title" data-wow-delay=".3s" ></div>
</template>


mounted() {
	new this.$wow.WOW().init({
      boxClass: "wow",
      animateClass: "animate__animated",
      offset: 0,
      mobile: true,
      live: true,
    });
 }


    

4、如果 wowjs在vue项目中使用有个奇葩的现象,就是只有网页第一屏的动画可以显示,鼠标往下滚动不仅动画没出来,就连原来的html元素也没有显示出来成了一片空白。。。
改造
1、在node_modules/wowjs/dist/wowjs.js这个源文件里

//源代码
//WOW.prototype.isVisible = function(box) {
 //     var bottom, offset, top, viewBottom, viewTop;
 //     offset = box.getAttribute('data-wow-offset') || this.config.offset;
 //     viewTop = window.pageYOffset;
 //     viewBottom = viewTop + Math.min(this.element.clientHeight, this.util().innerHeight()) - offset;
 //     top = this.offsetTop(box);
//      bottom = top + box.clientHeight;
 //     return top <= viewBottom && bottom >= viewTop;
//    };


//修改后
 WOW.prototype.isVisible = function(box) {
      var bottom, offset, top, viewBottom, viewTop;
      offset = box.getAttribute('data-wow-offset') || this.config.offset;
      viewTop = (this.config.scrollContainer && this.config.scrollContainer.scrollTop) || window.pageYOffset||document.body.scrollTop;
      viewBottom = viewTop + Math.min(this.element.clientHeight, this.util().innerHeight()) - offset;
      top = this.offsetTop(box);
      bottom = top + box.clientHeight;
      return top <= viewBottom && bottom >= viewTop;
    };



2、将false 改为true
//源代码
Util.prototype.addEvent = function(elem, event, fn) {
      if (elem.addEventListener != null) {
        return elem.addEventListener(event, fn, false);
      } else if (elem.attachEvent != null) {
        return elem.attachEvent("on" + event, fn);
      } else {
        return elem[event] = fn;
      }
    };

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值