這篇文章主要介紹了怎么使用vue實現(xiàn)動畫效果的相關(guān)知識,內(nèi)容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇怎么使用vue實現(xiàn)動畫效果文章都會有所收獲,下面我們一起來看看吧。
創(chuàng)新互聯(lián)于2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都做網(wǎng)站、網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元通川做網(wǎng)站,已為上家服務(wù),為通川各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220
1.作用
在插入,更新,移除DOM元素時,在合適的時候給元素添加樣式類名。
2.寫法
準備好樣式:元素進入的樣式
<template>
<div>
<button @click="isShow = !isShow">隱藏展示</button>
<transition name="hidden" appear>
<h2 v-show="isShow">隱藏展示</h2>
</transition>
</div>
</template>
<script>
export default {
name: "Test",
data() {
return {
isShow: true
};
}
};
</script>
<style scoped>
h2 {
background-color: orange;
}
.hidden-enter-active {
animation: shanyu 1s;
}
.hidden-leave-active {
animation: shanyu 1s reverse;
}
@keyframes shanyu {
from {
transform: translateX(-100%);
}
to {
transform: translateX(0px);
}
}
</style>
3.樣式
需要先有這個animate.css哦
npm i animate.css
1.v-enter:進入的起點
2.v-enter-active:進入過程中
3.v-enter-to:進入的終點
<template>
<div>
<button @click="isShow = !isShow">隱藏展示</button>
<transition-group name="shanyu" appear>
<h2 v-show="isShow" key = '1'>隱藏展示</h2>
<h2 v-show="isShow" key = '2'>隱藏展示</h2>
</transition-group>
</div>
</template>
<script>
export default {
name: "Test2",
data() {
return {
isShow: true
};
}
};
</script>
<style scoped>
h2 {
background-color: rgb(139, 37, 255);
}
/* 進入的起點,離開的起點 */
.shanyu-enter,
.shanyu-leave-to {
transform: translateX(-100%);
}
.shanyu-enter-active,.shanyu-leave-active{
transition: .5s linear;
}
/* 進入的終點離開的終點 */
.shanyu-enter-to,
.shanyu-leave {
transform: translateX(0);
}
</style>
元素離開的樣式:
1.V-leave:離開的起點
2.V-leave-active:離開過程中
3.V-leave-to:離開的終點
4.使用<transition>包裹要過度的元素,并配置name屬性
<transitionname="hello">
<h2v-show=" isShow">你好啊! </h2>
</transition>
備注:若有多個元素需要過度,則需要使用: <transition-group>, 且每個元素都要指定key值。
<transition-group name="shanyu" appear>
<h2 v-show="isShow" key = '1'>隱藏展示</h2>
<h2 v-show="isShow" key = '2'>隱藏展示</h2>
</transition-group>
關(guān)于“怎么使用vue實現(xiàn)動畫效果”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“怎么使用vue實現(xiàn)動畫效果”知識都有一定的了解,大家如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享標題:怎么使用vue實現(xiàn)動畫效果
本文來源:http://chinadenli.net/article36/jggosg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、網(wǎng)站排名、網(wǎng)站改版、企業(yè)網(wǎng)站制作、品牌網(wǎng)站設(shè)計、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)