显性的过渡持续时间
作者:互联网
2.2.0 新增
在很多情况下,Vue 可以自动得出过渡效果的完成时机。默认情况下,Vue 会等待其在过渡效果的根元素的第一个
transitionend
或animationend
事件。然而也可以不这样设定——比如,我们可以拥有一个精心编排的一系列过渡效果,其中一些嵌套的内部元素相比于过渡效果的根元素有延迟的或更长的过渡效果。
在这种情况下你可以用
<transition>
组件上的duration
prop 定制一个显性的过渡持续时间 (以毫秒计):
<transition :duration="1000">...</transition>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS 动画</title>
<script src="./vue.js"></script>
<style>
.hzhBounce-enter-active {
animation: hzh-bounce-in .5s;
}
.hzhBounce-leave-active {
animation: hzh-bounce-in .5s reverse;
}
@keyframes hzh-bounce-in {
0% {
transform: scale(0);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
</style>
</head>
<body>
<div id="hzh">
<button @click="hzhShow = !hzhShow">
切换显示
</button>
<transition name="hzhBounce" :duration="1000">
<p v-if="hzhShow">
黄子涵是帅哥!<br>
黄子涵是靓仔!<br>
黄子涵真厉害!<br>
黄子涵真聪明!
</p>
</transition>
</div>
<script>
new Vue({
el: '#hzh',
data: { hzhShow: true }
})
</script>
</body>
你也可以定制进入和移出的持续时间:
<transition :duration="{ enter: 500, leave: 800 }">...</transition>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>显性的过渡持续时间</title>
<script src="./vue.js"></script>
<style>
.hzhBounce-enter-active {
animation: hzh-bounce-in .5s;
}
.hzhBounce-leave-active {
animation: hzh-bounce-in .5s reverse;
}
@keyframes hzh-bounce-in {
0% {
transform: scale(0);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
</style>
</head>
<body>
<div id="hzh">
<button @click="hzhShow = !hzhShow">
切换显示
</button>
<transition name="hzhBounce" :duration="{ enter: 500, leave: 800 }">
<p v-if="hzhShow">
黄子涵是帅哥!<br>
黄子涵是靓仔!<br>
黄子涵真厉害!<br>
黄子涵真聪明!
</p>
</transition>
</div>
<script>
new Vue({
el: '#hzh',
data: { hzhShow: true }
})
</script>
</body>
标签:scale,持续时间,transform,bounce,hzh,animation,过渡,显性 来源: https://www.cnblogs.com/Huang-zihan/p/16345163.html