vue中transition動(dòng)畫(huà)使用(移動(dòng)端頁(yè)面切換左右滑動(dòng)效果)
例子一:(簡(jiǎn)單進(jìn)入和離開(kāi)動(dòng)畫(huà))
- 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); } /* 進(jìn)入的起點(diǎn)、離開(kāi)的終點(diǎn) */ .hello-enter, .hello-leave-to { transform: translateX(-100%); } .hello-enter-active, .hello-leave-active { transition: 0.5s linear; } /* 進(jìn)入的終點(diǎn)、離開(kāi)的起點(diǎn) */ .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>動(dòng)畫(huà)</h1> <button @click="isShow = !isShow">點(diǎn)擊顯示/隱藏</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ā)布回調(diào)執(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>
例子二:(移動(dòng)端上頁(yè)面進(jìn)入和離去動(dòng)畫(huà))
<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庫(kù) 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">超級(jí)管理員!</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>```
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
在vue項(xiàng)目中利用popstate處理頁(yè)面返回的操作介紹
這篇文章主要介紹了在vue項(xiàng)目中利用popstate處理頁(yè)面返回的操作介紹,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08FastApi+Vue+LayUI實(shí)現(xiàn)前后端分離的示例代碼
本文主要介紹了FastApi+Vue+LayUI實(shí)現(xiàn)前后端分離的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11vue使用@include或@mixin報(bào)錯(cuò)的問(wèn)題及解決
這篇文章主要介紹了vue使用@include或@mixin報(bào)錯(cuò)的問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02Vue3中無(wú)法為el-tree-select設(shè)置反選問(wèn)題解析
這篇文章主要介紹了Vue3中無(wú)法為el-tree-select設(shè)置反選問(wèn)題分析,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04vue運(yùn)行報(bào)錯(cuò)cache-loader的解決步驟
最近運(yùn)行vue項(xiàng)目的時(shí)候報(bào)錯(cuò)了,通過(guò)查找相關(guān)資料最終解決,下面這篇文章主要給大家介紹了關(guān)于vue運(yùn)行報(bào)錯(cuò)cache-loader的解決步驟,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-02-02Vue如何調(diào)用接口請(qǐng)求頭增加參數(shù)
這篇文章主要介紹了Vue如何調(diào)用接口請(qǐng)求頭增加參數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01vuex項(xiàng)目中登錄狀態(tài)管理的實(shí)踐過(guò)程
由于狀態(tài)零散地分布在許多組件和組件之間的交互中,大型應(yīng)用復(fù)雜度也經(jīng)常逐漸增長(zhǎng),為了解決這個(gè)問(wèn)題,Vue 提供 vuex,這篇文章主要給大家介紹了關(guān)于vuex項(xiàng)目中登錄狀態(tài)管理的相關(guān)資料,需要的朋友可以參考下2021-09-09詳解Vue Elememt-UI構(gòu)建管理后臺(tái)
本篇文章給大家詳細(xì)分享了Vue Elememt-UI構(gòu)建管理后臺(tái)的過(guò)程以及相關(guān)代碼實(shí)例,一起參考學(xué)習(xí)下。2018-02-02