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 让页面滚动更有趣~ 的相关文章

  • 六、Vite 常用第三方库(axios、mockjs、sass、echars、element-plus、开箱即用)

    文章目录 一 参考 二 vite 创建 Vue 项目工程 2 1 create vite和vite的关系是什么呢 2 2 vue团队希望弱化vite的一个存在感 但是我们去学习的时候不能弱化的 2 3 创建工程 三 第三方库的安装 开箱即用
  • 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
  • vue3-vant4-vite-pinia-axios-less学习日记

    代码地址 GitHub vue3 vant4 vite pinia axios less 效果如图 1 首页为导航栏 2 绑定英雄页 3 注册页 4 英雄列表页 5 后面不截图了 没啥了 模块 1 vant4 按需引入组件样式文档 2 安装
  • vue3 + vite 在线预览docx, pdf, pptx(内外网)并实现移动端适配

    一 内网 1 docx 使用docx preview 安装插件 npm i docx preview S 引入依赖 docx import renderAsync from docx preview let docx import meta
  • You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to ex

    vue3项目启动之后 会提示如下警告 You are running the esm bundler build of vue i18n It is recommended to configure your bundler to expl
  • Vue常用的修饰符有哪些?分别有什么应用场景?

    一 修饰符是什么 在程序世界里 修饰符是用于限定类型以及类型成员的声明的一种符号 在Vue中 修饰符处理了许多DOM事件的细节 让我们不再需要花大量的时间去处理这些烦恼的事情 而能有更多的精力专注于程序的逻辑处理 vue中修饰符分为以下五种
  • Vue3中的computed函数详解

    计算属性是Vue中常用的一种方式 主要用于在模板中放置逻辑计算 方便开发者进行数据操作和展示 在Vue3中 计算属性依然是非常重要的一种功能 而computed函数则更加的方便计算属性的使用 本文将对Vue3中的computed函数进行详细
  • Vue3的fragment

    vue2时 组件的模板结构中出现多个标签时 需要使用根标签 vue3时 组件的模板结构中出现多个标签时 可以不用根标签 这是因为vue3会自动将多个标签用fragment包裹 举个例子 main js import createApp fr
  • 25_Vue3路由-VueRouter的基本使用及动态路由和路由嵌套

    Vue3路由之Vue router的基本使用及路由嵌套和动态路由 认识前端路由 路由其实是网络工程中的一个术语 在架构一个网络时 非常重要的两个设备就是路由器和交换机 当然 目前在我们生活中路由器也是越来越被大家所熟知 因为我们生活中都会用
  • vue3.0基础知识浅谈

    vue3 0 首先创建vue3 0 项目 相比于vue2的变化 1 模板中可以没有根标签 2 main js中变化 组合API 一 setup 1 作用 2 返回值 3 注意点 4 参数 二 Ref函数 三 reactive函数 四 Ref
  • 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-实战-04-管理后台表单校验-layout-菜单组件封装

    目录 1 自定义校验规则 2 layout组件静态页面搭建 3 logo组件封装 4 左侧菜单静态组件搭建 4 1 动态获取菜单数据 4 2 封装菜单动态展示组件 4 3 配置菜单名称 隐藏 图标属性 4 4 菜单刷新定位当前菜单 5 内容
  • vue3 父子组件传参

    父向子传参 父组件
  • electron-vue2 项目初始化

    不要使用网上或者 github 的模板初始化项目 直接上代码 安装 vuecli 脚手架 npm update vue cli 初始化 project name 项目 vue create project name 进入项目 cd proj
  • vue3组件之间通信(三)——爷孙组件传递属性和方法

    文章目录 1 setup函数传递属性和方法 attrs 1 代码 2 主要代码和详细讲解 3 注意点 2 script setup 语法糖传递属性和方法 1 代码 2 主要代码和详细讲解 3 注意点 前言 爷孙组件使用prop一层一层传值和
  • vue3+ts实现todolist功能

    先看一下实现效果 可以看到内部实现的内容有enter输入 单项删除 全选 以及删除选中项等功能 具体在实现前需要常见有ts的vue3项目 项目创建 具体项目创建 就是 vue create 项目名称 在创建后 选择的时候有vue2和vue3
  • vue项目中批量删除如何实现的

    简单回答 与单个删除的接口为同一个 然后通过数组对象的id来删除
  • 【Vue3】在Vue3中使用reactive定义的响应式失效

    Vue3 在Vue3中使用reactive定义的响应式失效 文章目录 Vue3 在Vue3中使用reactive定义的响应式失效 Vue3 在Vue3中使用reactive定义的响应式失效 后面查出原因 解决办法 总结 Vue3 在Vue3
  • vue3使用babel-plugin-import按需引入element-plus

    vue3使用babel plugin import按需引入element plus 2022年6月13日更新 用babel plugin import按需引入element plus会有问题 用官方推荐的方式真香了 以下是链接 https

随机推荐