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

简介: 本文介绍了如何在Vue3项目中集成wow.js库,通过实现滚动动画效果来增强页面的动态性和趣味性,并提供了详细的使用示例和参数说明。

前言

项目是基于Vue3+Element plus框架设计的,本来使用Element plus的Loading加载动效已经是满足项目需求的,但是感觉AntDesign的加载动效图标好看一点点,于是自行实现一个基于Vue3,以及仿AntDesign的加载动效的示例。其主要用到Vue3的createVNode和render函数。

一、示例代码

(1)/src/utils/antdLodingUtil/antdLoding.vue

<template>
  <transition name="animation">
    <div class="diy-loading-wrap" v-if="isOpen">
     <div class="diy-loading-wrap-content">

      <div class="diy-loading-wrap-content-spin">
        <div class="ant-spin ant-spin-spinning">
          <span class="ant-spin-dot ant-spin-dot-spin">
            <i class="ant-spin-dot-item"></i>
            <i class="ant-spin-dot-item"></i>
            <i class="ant-spin-dot-item"></i>
            <i class="ant-spin-dot-item"></i>
          </span>
        </div>
      </div>

      <p class="diy-loading-wrap-content-p">{
   
   {
   
    text }}</p>
     </div>
    </div>
  </transition>
</template>

<script>
export default {
   
   
  data() {
   
   
    return {
   
   
      isOpen: false,
      text: '数据正在加载中...',
    }
  },
}
</script>

<style lang="less" scoped>
  :root {
   
   
    --el-mask-color: rgba(255, 255, 255, 0.9);
    --el-transition-duration: 0.3s;
    --el-transition-duration-fast: 0.2s;
    --el-loading-spinner-size: 42px;
    --el-loading-fullscreen-spinner-size: 50px;
  }

  /* animation 动画 */
  .animation-enter-active{
   
   
    animation: animationAction 0.3s;
  }

  .animation-leave-active{
   
   
    animation: animationAction 0.5s reverse;
  }

  @keyframes animationAction {
   
   
    0% {
   
   
      opacity: 0;
    }

    100% {
   
   
      opacity: 1;
    }
  }
  /* / animation 动画 */

  .diy-loading-wrap {
   
   
    position: absolute;
    z-index: 2000;
    background-color: var(--el-mask-color);
    margin: 0;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    transition: opacity var(--el-transition-duration);
  }

  .diy-loading-wrap .diy-loading-wrap-content {
   
   
    top: 50%;
    margin-top: calc((0px - var(--el-loading-spinner-size)) / 2);
    width: 100%;
    text-align: center;
    position: absolute;
  }

  .diy-loading-wrap .diy-loading-wrap-content .diy-loading-wrap-content-spin {
   
   

    .ant-spin {
   
   
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      color: #000000d9;
      font-size: 14px;
      font-variant: tabular-nums;
      line-height: 1.5715;
      list-style: none;
      font-feature-settings: tnum;
      position: absolute;
      display: none;
      color: #1890ff;
      text-align: center;
      vertical-align: middle;
      opacity: 0;
      transition: transform .3s cubic-bezier(.78,.14,.15,.86)
    }

    .ant-spin-spinning {
   
   
      position: static;
      display: inline-block;
      opacity: 1
    }

    .ant-spin-dot {
   
   
      position: relative;
      display: inline-block;
      font-size: 20px;
      width: 1em;
      height: 1em
    }

    .ant-spin-dot-spin {
   
   
      transform: rotate(45deg);
      animation: antRotate 1.2s infinite linear
    }

    .ant-spin-dot-item {
   
   
      position: absolute;
      display: block;
      width: 9px;
      height: 9px;
      background-color: #1890ff;
      border-radius: 100%;
      transform: scale(.75);
      transform-origin: 50% 50%;
      opacity: .3;
      animation: antSpinMove 1s infinite linear alternate
    }

    .ant-spin-dot-item:nth-child(1) {
   
   
      top: 0;
      left: 0;
    }
    .ant-spin-dot-item:nth-child(2) {
   
   
      top: 0;
      right: 0;
      animation-delay: .4s;
    }
    .ant-spin-dot-item:nth-child(3) {
   
   
      right: 0;
      bottom: 0;
      animation-delay: .8s;
    }

    .ant-spin-dot-item:nth-child(4) {
   
   
      bottom: 0;
      left: 0;
      animation-delay: 1.2s;
    }

    @keyframes antRotate {
   
   
      to {
   
   
        transform:rotate(405deg);
      }
    }

    @keyframes antSpinMove {
   
   
      to {
   
   
        opacity: 1;
      }
    }
  }

  .diy-loading-wrap .diy-loading-wrap-content .diy-loading-wrap-content-p {
   
   
    margin: 5px auto 0 auto;
    color: #1890ff;
    font-size: 14px;
  }  
</style>

(2)/src/utils/antdLodingUtil/antdLoding.js

import {
   
    createVNode, render } from 'vue'
import loading from './antdLoding.vue'

let instance

/**
 * 打开仿 Antd 加载的方法
 * @param {*} option 
 */
function showLoading(option) {
   
   
  instance = createVNode(loading, option)
  render(instance, document.querySelector('body'))
  instance.component.data.isOpen = true
}

/**
 * 关闭仿 Antd 加载的方法
 */
function hideLoading() {
   
   
  if (instance) {
   
   
    instance.component.data.isOpen = false
  }
}

export {
   
   
  showLoading,
  hideLoading
}

(3)/src/views/Example/AntdLoding/index.vue

<template>
    <div style="position: fixed; z-index: 9999; padding: 100px">
      <el-button @click="handleOpenAntdLoding($event)" type="primary" size="small">open</el-button>
      <el-button @click="handleCloseAntdLoding($event)" type="danger" size="small">close</el-button>
    </div>
</template>

<script>
export default {
   
   
  data() {
   
   
    return {
   
   

    }
  },
  methods: {
   
   
    /**
     * 打开仿 Antd 加载的句柄方法
     */
    handleOpenAntdLoding(evt) {
   
   
      this.$elementUtil.handleElButtonBlur(evt)
      this.$antdLodingUtil.showLoading({
   
    author: '帅龍之龍' })
    },

    /**
     * 关闭仿 Antd 加载的句柄方法
     */
    handleCloseAntdLoding(evt) {
   
   
      this.$elementUtil.handleElButtonBlur(evt)
      this.$antdLodingUtil.hideLoading()
    }
  }
}
</script>

(4)/src/main.ts

// 引入仿Antd加载器工具并配置为全局方法
import * as antdLodingUtil from '@/utils/antdLodingUtil/antdLoding'
app.config.globalProperties.$antdLodingUtil = antdLodingUtil

二、运行效果

目录
相关文章
|
6月前
|
JSON 自然语言处理 前端开发
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
296 72
【01】对APP进行语言包功能开发-APP自动识别地区ip后分配对应的语言功能复杂吗?-成熟app项目语言包功能定制开发-前端以uniapp-基于vue.js后端以laravel基于php为例项目实战-优雅草卓伊凡
|
5月前
|
JavaScript 安全 前端开发
关于Node.js,一定要学这个10+万Star项目 !!
一篇关于Node.js的宝藏项目——Node.js Best Practices。该项目在GitHub上已有102k Star,汇集了100+条最佳实践,涵盖架构、安全、性能等多方面。每条实践不仅有简明说明和详细解释,还附带代码示例及资源链接。文中通过三个实战案例(利用CPU多核、避免阻塞事件循环、使用中间件处理错误)展示了其实际应用价值,并推荐了几条对前端转Node.js开发者特别有用的最佳实践。强烈建议每位Node.js开发者学习此项目,理解“怎么做”与“为什么要这么做”,以提升开发能力。
160 3
|
7月前
|
人工智能 JavaScript 关系型数据库
【02】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-ui设计图figmaUI设计准备-figma汉化插件-mysql数据库设计-优雅草卓伊凡商业项目实战
【02】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-ui设计图figmaUI设计准备-figma汉化插件-mysql数据库设计-优雅草卓伊凡商业项目实战
237 14
【02】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-ui设计图figmaUI设计准备-figma汉化插件-mysql数据库设计-优雅草卓伊凡商业项目实战
|
7月前
|
前端开发 JavaScript Java
【03】Java+若依+vue.js技术栈实现钱包积分管理系统项目-若依框架搭建-服务端-后台管理-整体搭建-优雅草卓伊凡商业项目实战
【03】Java+若依+vue.js技术栈实现钱包积分管理系统项目-若依框架搭建-服务端-后台管理-整体搭建-优雅草卓伊凡商业项目实战
334 13
【03】Java+若依+vue.js技术栈实现钱包积分管理系统项目-若依框架搭建-服务端-后台管理-整体搭建-优雅草卓伊凡商业项目实战
|
7月前
|
SQL JavaScript 安全
【04】Java+若依+vue.js技术栈实现钱包积分管理系统项目-若依框架二次开发准备工作-以及建立初步后端目录菜单列-优雅草卓伊凡商业项目实战
【04】Java+若依+vue.js技术栈实现钱包积分管理系统项目-若依框架二次开发准备工作-以及建立初步后端目录菜单列-优雅草卓伊凡商业项目实战
296 11
【04】Java+若依+vue.js技术栈实现钱包积分管理系统项目-若依框架二次开发准备工作-以及建立初步后端目录菜单列-优雅草卓伊凡商业项目实战
|
7月前
|
人工智能 JavaScript 安全
【01】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-需求改为思维导图-设计数据库-确定基础架构和设计-优雅草卓伊凡商业项目实战
【01】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-需求改为思维导图-设计数据库-确定基础架构和设计-优雅草卓伊凡商业项目实战
305 13
【01】Java+若依+vue.js技术栈实现钱包积分管理系统项目-商业级电玩城积分系统商业项目实战-需求改为思维导图-设计数据库-确定基础架构和设计-优雅草卓伊凡商业项目实战
|
10月前
|
JavaScript 前端开发 API
Vue.js响应式原理深度解析:从Vue 2到Vue 3的演进
Vue.js响应式原理深度解析:从Vue 2到Vue 3的演进
271 17
|
10月前
|
CDN
如何在项目中使用Moment.js库?
如何在项目中使用Moment.js库?
|
10月前
|
JavaScript 前端开发 安全
JavaScript与TypeScript的对比,分析了两者的特性及在实际项目中的应用选择
本文深入探讨了JavaScript与TypeScript的对比,分析了两者的特性及在实际项目中的应用选择。JavaScript以其灵活性和广泛的生态支持著称,而TypeScript通过引入静态类型系统,提高了代码的可靠性和可维护性,特别适合大型项目。文章还讨论了结合使用两种语言的优势,以及如何根据项目需求和技术背景做出最佳选择。
926 4
|
10月前
|
资源调度 前端开发 JavaScript
vite3+vue3 实现前端部署加密混淆 javascript-obfuscator
【11月更文挑战第10天】本文介绍了在 Vite 3 + Vue 3 项目中使用 `javascript-obfuscator` 实现前端代码加密混淆的详细步骤,包括安装依赖、创建混淆脚本、修改 `package.json` 脚本命令、构建项目并执行混淆,以及在 HTML 文件中引用混淆后的文件。通过这些步骤,可以有效提高代码的安全性。
1068 2