例子一:(简单进入和离开动画)

demo1

<template><div><button @click="isShow = !isShow">显示/隐藏</button><transition-group name="hello" appear><h1 v-show="!isShow" key="1">vue2!</h1><h1 v-show="isShow" key="2">VUE3!</h1></transition-group></div>
</template><script>
export default {name: 'Test',data () {return {isShow: true}},
}
</script><style scoped>
h1 {color: #fff;background-color: rgb(27, 247, 255);
}
/* 进入的起点、离开的终点 */
.hello-enter,
.hello-leave-to {transform: translateX(-100%);
}
.hello-enter-active,
.hello-leave-active {transition: 0.5s linear;
}
/* 进入的终点、离开的起点 */
.hello-enter-to,
.hello-leave {transform: translateX(0);
}
</style>

demo1

<!--* @Description: * @Author: Ran junlin* @Date: 2021-09-24 14:07:16* @LastEditTime: 2022-02-10 17:29:28* @LastEditors: Ran junlin
-->
<template><div id="app"><h2>pubsub中间件消息订阅:</h2><hr /><v-hello /><v-add /><hr /><h1>动画</h1><button @click="isShow = !isShow">点击显示/隐藏</button><transition name="myHello" appear mode="in-out"><div v-show="isShow" class="demio">hello vue !</div></transition></div>
</template><script>
import pubsub from 'pubsub-js'
import vAdd from '@/components/v-add'
import vHello from '@/components/v-hello'
export default {name: 'App',components: {vHello,vAdd},data () {return {pubId: '',isShow: true}},created () {},mounted () {// 消息订阅this.pubId = pubsub.subscribe('hello', (name, data) => {console.log('有人发布了消息,消息发布回调执行', name, data);})},beforeDestroy () {pubsub.unsubscribe(this.pubId)},methods: {},
}
</script><style>
.bm-view {width: 100%;height: 600px;
}
* {touch-action: pan-y;
}
#app {font-family: Avenir, Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;text-align: center;color: #2c3e50;
}
#container {margin: 0 auto;width: 1500px;height: 1000px;
}
.demio {margin: 20px auto;width: 80%;height: 300px;line-height: 300px;text-align: center;font-size: 50px;background-color: rgb(94, 245, 182);
}.myHello-enter-active {animation: showHello 0.5s linear;
}
.myHello-leave-active {animation: showHello 0.5s linear reverse;
}
@keyframes showHello {from {transform: translateX(-100%);transform: scaleX(0.2);}to {transform: translateX(-100%);transform: scaleX(1.1);}
}
</style>

例子二:(移动端上页面进入和离去动画)

<template>
<div id="app"><transition :name="animation" mode="in-out" appear><router-view class="global-router" /></transition>
</div>
</template><script>
export default {name: 'App',data() {return {animation: ''};},watch: {$route(to, from) {wexinShare()if (!from.meta.pageNum=== undefined) {this.animation = 'none';} else {this.animation = to.meta.pageNum> from.meta.pageNum? 'left' : 'right';}}},
};
</script><style lang="less">
#app {font-family: 'Avenir', Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;color: #2c3e50;height: 100vh;width: 100vw;overflow: hidden;font-size: 15px;
}
</style><style lang="less" scoped>
.global-router {position: absolute;top: 0;left: 0;right: 0;bottom: 0;
}.left-enter {transform: translateX(100%);
}.right-enter {transform: translateX(-100%);
}.left-enter-active,
.right-enter-active {position: relative;z-index: 999;transition: all 0.4s;
}.left-leave-active,
.right-leave-active {position: relative;z-index: -1;
}
</style>

例子三:(利用第三方css库 Animate

<template><div><button @click="isShow = !isShow">显示/隐藏</button><transition-group appearname="animate__animated animate__bounce" enter-active-class="animate__swing"leave-active-class="animate__backOutUp"><h1 v-show="!isShow" key="1">你好啊!</h1><h1 v-show="isShow" key="2">超级管理员!</h1></transition-group></div>
</template><script>import 'animate.css'export default {name:'Test',data() {return {isShow:true}},}
</script><style scoped>h1{background-color: orange;}</style>```

vue中transition动画(移动端页面切换左右滑动效果)相关推荐

  1. vue中使用动画vue-particles实现背景粒子酷炫效果

    参考官网:https://vue-particles.netlify.com/ 安装插件 npm install vue-particles --save-dev 在main.js中引入 import ...

  2. Vue实战项目开发--Vue中的动画特效

    项目的源代码在GitHub上:点击查看 目录 vue中的css动画原理 在Vue中使用Animate.css库 在Vue中同时使用过渡属性和动画 Vue中的Js动画与Velocity.js的结合 Vu ...

  3. vue中过渡动画(类名实现方式)

    vue中过渡动画分为两类,一类是进场动画,一类是出场动画 要实现上面的进场动画,主要有三种方式:类名,css动画库,js函数 类名 本质就是动态添加类名实现动画 在进入/离开的过渡中,会有 6 个 c ...

  4. Vue基础实现bilibili移动端页面

    Vue基础实现bilibili移动端页面 一.Vue基础实现bilibili移动端页面 一.Vue基础实现bilibili移动端页面 简述:对于已经学到vue的同学,bilibili的页面布置难度不大 ...

  5. 在vue中使用flexible---移动端适配

    在vue中使用flexible-移动端适配 配置 flexible 安装 lib-flexible 在命令行中运行如下安装: npm i lib-flexible --save 引入 lib-flex ...

  6. Vue 中 CSS 动画原理

    下面这段代码,是点击按钮实现hello world显示与隐藏 <div id="root"><div v-if="show">hello ...

  7. vue中的倒计时跳转页面问题和axios网络请求this作用域问题

    一.前言 这两个是在日常开发中碰到的问题,网上都能查得到答案,但是我怕自己会忘记,姑且记录一下用作笔记吧. 二.vue倒计时跳转问题 1.案例 比如我们在一次网络请求结束之后,如果返回结果是成功,则倒 ...

  8. Vue+Element实现tab页多页面切换

    效果图GIF 源码地址 https://gitee.com/marlife/nav-tags.git 已经上传到Gitee(码云),代码拉下来之后: 1.执行安装命令:npm install 2.执行 ...

  9. 解决移动端scrollTo({behavior: “smooth“})滑动效果失效的问题

    js自带的scrollTo方法可以设置动画,滚动的效果,代码在电脑上正常,但是在手机上的时候就没有smooth的滑动效果了,只能僵硬的跳到某个位置,类似scrollTop赋值的效果,这里从一个博客看到 ...

最新文章

  1. php 最大数字,PHP 计算至少是其他数字两倍的最大数的实现代码
  2. POJ 3621 最优比率生成环
  3. loj 300 [CTSC2017]吉夫特 【Lucas定理 + 子集dp】
  4. opengl游戏引擎源码_跨平台渲染引擎之路:拨云见日
  5. 动态ADF火车:以编程方式添加火车停靠站
  6. 监控利器--Cacti
  7. android 自动化测试之monkeyrunner学习(三),自动化测试之Monkeyrunner
  8. android比较两个字符串,关于java:两个字符串的比较在android中不起作用
  9. s2 安恒 漏洞验证工具_Struts2漏洞利用工具下载(更新2017-V1.8版增加S2-045/S2-046)-阿里云开发者社区...
  10. 轻量级网络之GhostNet
  11. 钢笔墨水能否代替打印机墨水_喷墨打印机该用染料墨水还是颜料墨水?
  12. jsp 图片下载功能
  13. postgreSql版的occurs函数
  14. keil工具中fromelf生成汇编代码lst文件(armcc)
  15. android svg路径动画,Android和播放SVG动画
  16. 编译原理 —— 什么是语法分析
  17. unity2D制作一个2D游戏场景Tilemap
  18. linux 下建立硬链接和软连接
  19. 从翻译到产品本地化 Airbnb语言经理的出海建议
  20. 加州大学河滨分校计算机科学专业,美国加州大学河滨分校计算机科学硕士专业申请.pdf...

热门文章

  1. elasticsearchTemplate
  2. 如何设置滚动条样式?
  3. 内嵌于球的等边三棱柱
  4. 被带偏的“中国味道”!破发的卫龙,何以破局?
  5. 常见的JS事件汇总(简洁易懂)
  6. 【DL】第 4 章:自回归模型
  7. 适用于AG的AI:农业生产机器学习
  8. 手把手教你系列 - Particle粒子特效(上)
  9. win10开启Linux蓝屏,win10蓝屏重启进不去桌面解决方法。
  10. 联想发布全球首款骁龙 855 手机,最高 12G 内存,明年 1 月发售...