vue中transition動畫使用(移動端頁面切換左右滑動效果)
更新時間:2024年07月27日 10:07:25 作者:冷太陽a
這篇文章主要介紹了vue中transition動畫使用(移動端頁面切換左右滑動效果),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
例子一:(簡單進入和離開動畫)
- 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('有人發(fā)布了消息,消息發(fā)布回調執(zhí)行', 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 appear name="animate__animated animate__bounce" enter-active-class="animate__swing" leave-active-class="animate__backOutUp" > <h1 v-show="!isShow" key="1">你好?。?lt;/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>```總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
FastApi+Vue+LayUI實現(xiàn)前后端分離的示例代碼
本文主要介紹了FastApi+Vue+LayUI實現(xiàn)前后端分離的示例代碼,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11
Vue3中無法為el-tree-select設置反選問題解析
這篇文章主要介紹了Vue3中無法為el-tree-select設置反選問題分析,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04

