Vue3项目使用 wow.js 让页面滚动更有趣~

2023-05-16

wow.js是一个可以在页面滚动的过程中逐渐释放动画效果,让页面滚动更有趣的一个插件库。

官网:wow.js — Reveal Animations When Scrolling

本文就演示一下如何在Vue3项目使用 wow.js,颇为简单~

1、导入依赖,注意 wow.js 已经自带 animate.css

npm install wowjs --save-dev

2、在想要动画效果的 vue 页面,加载 wow.js 资源

<script>
import { WOW } from 'wowjs'

export default {
  data: () => ({

  }),
  mounted() {
    let 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
    });
    wow.init()
  },
}
</script>

<style src="wowjs/css/libs/animate.css"></style>

 3、在 vue 页面写上具有 wow.js 效果的html代码

<template>
  <div style="padding: 100px">
    <div class="wow rollIn" data-wow-duration="2s" data-wow-delay="3s" style="width: 100%; height: 100px; background-color: lightblue">wow rollIn</div>
    <div class="wow rollIn" data-wow-offset="10"  data-wow-iteration="10" style="width: 100%; height: 100px; background-color: lightgreen">wow rollIn</div>
  </div>
</template>

示例代码

src/views/Example/WOWjs/index.vue

<template>
  <div>
    <ul>
      <li class="wow rollIn" data-wow-duration="2s" data-wow-delay="3s" style="background-color: lightblue">wow rollIn</li>
      <li class="wow rollIn" data-wow-offset="10"  data-wow-iteration="10" style="background-color: lightgreen">wow rollIn</li>
      <li class="wow rollIn" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow rollIn</li>
      <li class="wow lightSpeedIn" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow lightSpeedIn</li>
      <li class="wow swing" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow swing</li>
      <li class="wow pulse" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow pulse</li>
      <li class="wow flip" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow flip</li>
      <li class="wow flipInX" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow flipInX</li>
      <li class="wow bounce" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow bounce</li>
      <li class="wow bounceInDown" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow bounceInDown</li>
      <li class="wow bounceInUp" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow bounceInUp</li>
      <li class="wow bounceInLeft" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow bounceInLeft</li>
      <li class="wow bounceInRight" :style="'background-color: ' + 'rgba(' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ', ' + Math.round(Math.random() * 255) + ',' + 0.8 + ')'">wow bounceInRight</li>
    </ul>
  </div>
</template>

<script>
import { WOW } from 'wowjs'

export default {
  data: () => ({

  }),
  mounted() {
    let 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
    });
    wow.init()
  },
}
</script>

<style lang="less" scoped>
  ul {
    width: auto;
    height: auto;
    padding: 100px 250px;
    list-style: none;

    li {
      width: 100%;
      height: 150px;
      margin: 50px 0;
      color: #fff;
      text-align: center;
      line-height: 150px;
      font-size: 20px;
    }
  }
</style>

<style src="wowjs/css/libs/animate.css"></style>

效果如下~

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Vue3项目使用 wow.js 让页面滚动更有趣~ 的相关文章

  • vue3.2 之 driver引导页的使用

    目录 vue3 2 之 driver引导页的使用 components driver index vue components driver steps ts 使用 效果 vue3 2 之 driver引导页的使用 安装 yarn add
  • vue3中ts全局声明再.vue文件中显示no-undef

    显示错误xxx is not defined eslintno undef 解决方法 参考 Why Eslint don t see global TypeScript types in vue files no undef 在 eslin
  • vue 3.0新特性之reactive与ref

    vue 3 0新特性 参考 https www cnblogs com Highdoudou p 9993870 html https www cnblogs com ljx20180807 p 9987822 html 性能优化 观察者机
  • vite 配置自动补全文件的后缀名

    vite 不建议自动补全 文件的后缀名的 const Home gt import views Home vue 文件是必须要加上 vue 的后缀名的 如果 想要像 webpack 一样的不用写 可以在vite config js中配置如下
  • vue3+vite 使用 postcss-pxtorem、autoprefixer 实现自适应和自动添加前缀

    自动添加前缀 自适应 1 安装 postcss pxtorem 和 autoprefixer npm install postcss pxtorem save npm i autoprefixer 2 vite config js引入并配置
  • Vue3.2中使用swiper实现层叠式轮播图

    介绍 在 vue3 中使用 swiper 实现缩略图的轮播图效果 具体如下图所示 代码
  • Vue常用的修饰符有哪些?分别有什么应用场景?

    一 修饰符是什么 在程序世界里 修饰符是用于限定类型以及类型成员的声明的一种符号 在Vue中 修饰符处理了许多DOM事件的细节 让我们不再需要花大量的时间去处理这些烦恼的事情 而能有更多的精力专注于程序的逻辑处理 vue中修饰符分为以下五种
  • vue3+vite中使用path-to-regexp以及相关的报错问题

    前言 path to regexp 该方法的作用是把字符串转为正则表达式 一般我们使用动态匹配路由的时候会用到这个 1 介绍path to regexp 更多点我查看 pathToRegexp pathToRegexp foo bar 打印
  • vue3项目修改浏览器的项目icon小图标

    修改vue3项目的浏览器的图标 vue2修改图标
  • Vue3 + Element Plus 按需引入 - 自动导入

    文章目录 1 前言 1 1 目的 1 2 最终效果 2 准备工作 3 按需引入 3 1 安装插件 3 2 修改 vite config ts 文件 4 其他 4 1 ElMessageBox 使用时报错 4 1 1 Eslint 报错 El
  • uni-app微信小程序开发自定义select下拉多选内容篇

    欢迎点击领取 前端面试题进阶指南 前端登顶之巅 最全面的前端知识点梳理总结 分享一个使用比较久的 技术框架公司的选型 uni app uni ui vue3 vite4 ts 需求分析 微信小程序 uni ui内容 1 创建一个自定义的下拉
  • Vue3全局提示(Message)

    Vue2全局提示 Message 可自定义设置以下属性 自动关闭的延时 duration 类型 number 单位ms 默认 3000ms 消息距离顶部的位置 top 类型 number 单位px 默认 30px 调用一次只展示一个提示 调
  • vue3+vite 全局组件注册与使用

    前言 vite和我们的webpack是不同的 这里没办法用require 但是他也有自己的引入文件的方法 是 import meta glob 实现效果 vite方法官方入口 功能 Vite 官方中文文档下一代前端工具链https cn v
  • 不习惯的 Vue3 起步六 の Echarts绘制下钻地图

    序 看过一些可视化大屏展示地图的例子 准备动手做做 既然要开始比制作 那么先把目标定好 做一个展示中国城市的下钻地图 使用 Vue3 Vite Typescript echarts 实现效果 准备工作 创建项目 因为准备使用Vue3 Vit
  • electron-vue2 项目初始化

    不要使用网上或者 github 的模板初始化项目 直接上代码 安装 vuecli 脚手架 npm update vue cli 初始化 project name 项目 vue create project name 进入项目 cd proj
  • Vue3 从入门到放弃 (第二篇.创建第一个Web应用)

    上一篇讲到了 Vue3的一些前期准备和环境配置 Vue3 从入门到放弃 第一篇 环境准备 Meta Qing的博客 CSDN博客 今天我们来讲讲 项目结构以及各个文件介绍 并且创建我们第一个WEB应用 我们继续上一篇 创建完工程结构 目录介
  • vue3中实现el-dialog弹窗

    vue3中的父子组件传递依然和vue2中的一样使用props和emit 但是写法略有不同 emit 自定义事件 子传父 props 父传子 父组件中
  • vue3中实现音频播放器APlayer

    前言 vue2的时候 分享了一个很好用的插件是vue aplayer 但是他是不支持vue3的 这里分享vue3使用APlayer来实现一个播放器的方法 实现效果 官方 git地址 点我 api地址 点我 实现步骤 1 安装 npm npm
  • Vue3状态管理库Pinia——核心概念(Store、State、Getter、Action)

    个人简介 个人主页 前端杂货铺 学习方向 主攻前端方向 正逐渐往全干发展 个人状态 研发工程师 现效力于中国工业软件事业 人生格言 积跬步至千里 积小流成江海 推荐学习 前端面试宝典 Vue2 Vue3 Vue2 3项目实战 Node js
  • 【vue3练习 -12】vue3使用readonly(),shallowReadonly()

    作用 把一个响应式 可以是ref定义的 也可以是reactive定义的 的数据变成只读的 不可以修改 使用场景 假如你的组件有个数据 但是你不希望在使用的时候修改他就可以把他变成只读的 用法示例 import readonly shallo

随机推荐