原版 wowjs 在 Vue2 项目中可以正常使用,但是放在 Vue3 项目中会报错。
报错信息:
Cannot set property 'getPropertyValue' of undefined
Vue3 项目中需要改用 wow.js
- 安装 wow.js(注意是 wow.js 不是 wowjs)
npm install wow.js --save
# or
yarn add wow.js
- 安装 animate.css
npm install animate.css --save
# or
yarn add animate.css
- 在 main.ts/main.js 中配置 animate.css
import animated from "animate.css";
app.use(animated);
- 在组件中使用 wow.js
import WOW from "wow.js";
mounted() {
var wow = new WOW({
boxClass: "wow", // animated element css class (default is wow)
animateClass: "animated", // animation css class (default is animated)
offset: 0, // distance to the element when triggering the animation (default is 0)
mobile: true, // trigger animations on mobile devices (default is true)
live: true, // act on asynchronously loaded content (default is true)
callback: function (box) {
// the callback is fired every time an animation is started
// the argument that is passed in is the DOM node being animated
},
scrollContainer: null, // optional scroll container selector, otherwise use window,
resetAnimation: true, // reset animation on end (default is true)
});
wow.init();
},
- 在要实现动画的HTML元素上配置参数,更多动画效果可参考 Animate.css
<section class="wow slideInLeft" data-wow-duration="2s" data-wow-delay="5s"></section>
<section class="wow slideInRight" data-wow-offset="10" data-wow-iteration="10"></section>
结语:没放在vue2中测试,可参考:https://blog.csdn.net/qq_45807943/article/details/109688908