本文已参与「新人创作礼」活动,一起开启掘金创作之路。
@[toc]
3.25Vue封装的过度与动画
3.25.1知识点总结
3.25.2案例
注意点1:最好有css动画基础,再练习这块,但我只是了解所以原封不动拷贝看效果就是,当了解即可。
【动画/过度】使用方式:
1)定义【动画/过度】样式名称
2)用标签包裹起来要实现动画的元素
使用动画方式:
<transition name="hello" appear>
<h1 v-show="isShow">你好啊!</h1>
</transition>
<style scoped>
h1{
background-color: orange;
}
.hello-enter-active{
animation: atguigu 0.5s linear;
}
.hello-leave-active{
animation: atguigu 0.5s linear reverse;
}
@keyframes atguigu {
from{
transform: translateX(-100%);
}
to{
transform: translateX(0px);
}
}
</style>
使用过度方式:
<style scoped>
h1{
background-color: orange;
}
/* 进入的起点、离开的终点 */
.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>
注意点2:动画效果来和去只写一个就行,另一个效果直接反转动画就是
注意点3:vue要求你想让谁实现动画效果,你就用标签把它包裹起来
<transition name="hello" appear>
<h1 v-show="isShow">你好啊!</h1>
</transition>
注意点4:这个和