vue使用 Swiper Animate实现超级酷炫的滚屏动画

本文主要是介绍vue使用 Swiper Animate实现超级酷炫的滚屏动画,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

    • 功能
    • 1.下载 swiper
    • 2.初始化swiper
    • 3.使用swiper Anamate
    • 4.最终效果

功能

1.鼠标滚用切换页面,并附带超酷的动画特效
2.感受页面内容从四面八方向你奔赴而来的感觉
3.animate超多原生css3动画特效任你选择
4.大屏数据,一屏页面,带给你无与伦比的视图体验

1.下载 swiper

npm install swiper --save

2.初始化swiper

html片段

<template><div class="swiper-container" style='background-color: #020D35;height:100vh;'><div class="swiper-wrapper"><div class="swiper-slide" style="height: 100vh;"><Home></Home></div><div class="swiper-slide" style='height:100vh;'><TeachersData></TeachersData></div><div class="swiper-slide" style='height:100vh;'><WisdomEducational></WisdomEducational></div><div class="swiper-slide" style='height:100vh;'><ResearchResults></ResearchResults></div></div><!-- 如果需要导航按钮 --><!-- <div class="swiper-button-prev"></div><div class="swiper-button-next"></div> --><!-- 如果需要滚动条 --><div class="swiper-scrollbar"></div></div>
</template>

js片段

<script>
import Home from "./home/home"
import TeachersData from "./teachersData/teachersData"
import Swiper from "swiper"
import WisdomEducational from "./wisdomEducational/wisdomEducational"
import ResearchResults from "./researchResults/researchResults"export default {components:{Home,TeachersData,WisdomEducational,ResearchResults},data(){return{isShow: false}},created(){this.$nextTick(function(){  //因为初始化swiper需要获取dom节点,所以要将初始化的代码写入 this.$nexTick 里,或者写在mounted钩子函数里var mySwiper = new Swiper ('.swiper-container', {loop: false, // 循环模式选项speed:1000,mousewheel: true,direction : 'vertical',navigation: {nextEl: '.swiper-button-next',prevEl: '.swiper-button-prev',},				})  })	},mounted(){}
}
</script>

3.使用swiper Anamate

1.animate.js

[注]:因为swiper官网提供的js文件不是export方式导出的,所以我们引入时会报错,我在各大网站上找到里一个更改以后的js文件。
创建一个js文件 我这里命名为 animate.js,将以下代码复制到创建的js文件里
export function swiperAnimateCache() {const allBoxes = window.document.documentElement.querySelectorAll('.ani')for (var i = 0; i < allBoxes.length; i++) {allBoxes[i].attributes['style']? allBoxes[i].setAttribute('swiper-animate-style-cache', allBoxes[i].attributes['style'].value): allBoxes[i].setAttribute('swiper-animate-style-cache', ' ')allBoxes[i].style.visibility = 'hidden'}
}export function swiperAnimate(a) {clearSwiperAnimate()var b = a.slides[a.activeIndex].querySelectorAll('.ani')for (var i = 0; i < b.length; i++) {b[i].style.visibility = 'visible'const effect = b[i].attributes['swiper-animate-effect']? b[i].attributes['swiper-animate-effect'].value: ''b[i].className = b[i].className + ' ' + effect + ' ' + 'animated'const duration = b[i].attributes['swiper-animate-duration']? b[i].attributes['swiper-animate-duration'].value: ''// duration && styleconst delay = b[i].attributes['swiper-animate-delay']? b[i].attributes['swiper-animate-delay'].value: ''const style = b[i].attributes['style'].value + 'animation-duration:' + duration + ';-webkit-animation-duration:' + duration + ';' + 'animation-delay:' + delay + ';-webkit-animation-delay:' + delay + ';'// delay && (style = style )b[i].setAttribute('style', style)}
}export function clearSwiperAnimate() {var allBoxes = window.document.documentElement.querySelectorAll('.ani')for (var i = 0; i < allBoxes.length; i++) {allBoxes[i].attributes['swiper-animate-style-cache'] && allBoxes[i].setAttribute('style', allBoxes[i].attributes['swiper-animate-style-cache'].value)allBoxes[i].style.visibility = 'hidden'allBoxes[i].className = allBoxes[i].className.replace('animated', ' ')const effectValue = allBoxes[i].attributes['swiper-animate-effect'].value/* eslint-disable-next-line */allBoxes[i].attributes['swiper-animate-effect'] && (effectValue, allBoxes[i].className = allBoxes[i].className.replace(effectValue, ' '))}
}
  1. animate.css
    css文件在swiper官网上就有,传送门:animate.css
    在这里插入图片描述
    3.在需要使用的页面引入js 和 css文件
    js(在 script标签内部引入)
import * as swiperAni from '../../assets/animate/animate.js' //根据自己的路径进行引入

css(在style标签内部引入)

@import url('../../assets/animate/animate.min.css');

4.开始使用动画
js
在初始化swiper的代方法里加入以下代码 on 的这段代码

  this.$nextTick(function(){var mySwiper = new Swiper ('.swiper-container', {loop: false, // 循环模式选项speed:1000,mousewheel: true,direction : 'vertical',navigation: {nextEl: '.swiper-button-next',prevEl: '.swiper-button-prev',},on:{init: function(){swiperAni.swiperAnimateCache(this); //隐藏动画元素 swiperAni.swiperAnimate(this); //初始化完成开始动画}, slideChangeTransitionStart: function(){ swiperAni.swiperAnimate(this); //每个slide开始切换时也运行当前slide动画//this.slides.eq(this.activeIndex).find('.ani').removeClass('ani'); 动画只展现一次,去除ani类名} }})  })

html
给需要展示动画的dom节点上加入以下内容

//<Home class="ani" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="0s"></Home><template><div class="swiper-container" style='background-color: #020D35;height:100vh;'><div class="swiper-wrapper"><div class="swiper-slide" style="height: 100vh;"><Home class="ani" swiper-animate-effect="bounceInLeft" swiper-animate-duration="0.5s" swiper-animate-delay="0s"></Home></div></div>
</template>

class=“ani” 是必须要加的
swiper-animate-effect=“bounceInLeft” (动画的样式,这个根据animate.css官网上的演示,自行挑选)
动画演示
swiper-animate-duration=“0.5s” swiper-animate-delay=“0s” (动画持续的时间)

4.最终效果

在这里插入图片描述

这篇关于vue使用 Swiper Animate实现超级酷炫的滚屏动画的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/550305

相关文章

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

python设置环境变量路径实现过程

《python设置环境变量路径实现过程》本文介绍设置Python路径的多种方法:临时设置(Windows用`set`,Linux/macOS用`export`)、永久设置(系统属性或shell配置文件... 目录设置python路径的方法临时设置环境变量(适用于当前会话)永久设置环境变量(Windows系统

python使用try函数详解

《python使用try函数详解》Pythontry语句用于异常处理,支持捕获特定/多种异常、else/final子句确保资源释放,结合with语句自动清理,可自定义异常及嵌套结构,灵活应对错误场景... 目录try 函数的基本语法捕获特定异常捕获多个异常使用 else 子句使用 finally 子句捕获所

C++11右值引用与Lambda表达式的使用

《C++11右值引用与Lambda表达式的使用》C++11引入右值引用,实现移动语义提升性能,支持资源转移与完美转发;同时引入Lambda表达式,简化匿名函数定义,通过捕获列表和参数列表灵活处理变量... 目录C++11新特性右值引用和移动语义左值 / 右值常见的左值和右值移动语义移动构造函数移动复制运算符

Python对接支付宝支付之使用AliPay实现的详细操作指南

《Python对接支付宝支付之使用AliPay实现的详细操作指南》支付宝没有提供PythonSDK,但是强大的github就有提供python-alipay-sdk,封装里很多复杂操作,使用这个我们就... 目录一、引言二、准备工作2.1 支付宝开放平台入驻与应用创建2.2 密钥生成与配置2.3 安装ali

Spring Security 单点登录与自动登录机制的实现原理

《SpringSecurity单点登录与自动登录机制的实现原理》本文探讨SpringSecurity实现单点登录(SSO)与自动登录机制,涵盖JWT跨系统认证、RememberMe持久化Token... 目录一、核心概念解析1.1 单点登录(SSO)1.2 自动登录(Remember Me)二、代码分析三、

C#中lock关键字的使用小结

《C#中lock关键字的使用小结》在C#中,lock关键字用于确保当一个线程位于给定实例的代码块中时,其他线程无法访问同一实例的该代码块,下面就来介绍一下lock关键字的使用... 目录使用方式工作原理注意事项示例代码为什么不能lock值类型在C#中,lock关键字用于确保当一个线程位于给定实例的代码块中时

MySQL 强制使用特定索引的操作

《MySQL强制使用特定索引的操作》MySQL可通过FORCEINDEX、USEINDEX等语法强制查询使用特定索引,但优化器可能不采纳,需结合EXPLAIN分析执行计划,避免性能下降,注意版本差异... 目录1. 使用FORCE INDEX语法2. 使用USE INDEX语法3. 使用IGNORE IND

C# $字符串插值的使用

《C#$字符串插值的使用》本文介绍了C#中的字符串插值功能,详细介绍了使用$符号的实现方式,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧... 目录$ 字符使用方式创建内插字符串包含不同的数据类型控制内插表达式的格式控制内插表达式的对齐方式内插表达式中使用转义序列内插表达式中使用

flask库中sessions.py的使用小结

《flask库中sessions.py的使用小结》在Flask中Session是一种用于在不同请求之间存储用户数据的机制,Session默认是基于客户端Cookie的,但数据会经过加密签名,防止篡改,... 目录1. Flask Session 的基本使用(1) 启用 Session(2) 存储和读取 Se