vue 2.x 过渡和动画的使用
最近在开发移动端app的时候,多处地方需要使用transition组件去增添一些效果,例如: picker, popup, toast等自定义组件, 所以记录了一下
使用方式
- 通常配合v-show使用
<!--
这里模拟一个 picker 的效果
布局css :
外层fixed + top0 bottom 0
内层 absoluted bottom 0 height: 50px
-->
<!--
点击按钮 外层会在 0.4s 内 从opacity: 0 -> opacity: 1,
内层则会 0.4s 内从底部往上移动
-->
<template>
<div class="container">
<button @click="mark = !mark">toggle</button>
<transition name="fade">
<div v-show="mark">
<div class="inner">
这里是内容
</div>
</div>
</transition>
</div>
</template>
<script>
export default {
data(){
return {
mark: false
}
}
}
</script>
<style scoped>
.inner{
transition: all 0.4s linear;
transform: transform: translate3d(-100%, 0, 0);;
}
.fade-enter, .fade-leave-to{
opacity: 0;
&.inner {
transform: translate3d(0, 0, 0);
}
}
.fade-enter-active, .fade-leave-active{
transition: all 0.4s linear;
}
</style>
内层也可再嵌套
transition
组件
具体参照 vue js 2.x.