页面结构
javascript
<div>
<span @click="checkBtn = '1'">1111</span> |
<span @click="checkBtn = '2'">2222</span>
</div>
<div >
<transition :name="transitionName" appear>
<ContractTrade v-if="checkBtn === '1'" key="1" @traded="$emit('traded')" />
<ContractTrade v-else key="2" @traded="$emit('traded')" />
</transition>
</div>
实现
javascript
const checkBtn = ref('1');
const transitionName = computed(() => {
if (checkBtn.value == '1') {
return 'slide-left';
} else {
return 'slide-right';
}
});
html
.contract-trade-wrap {
position: relative;
overflow: hidden;
}
// .slide-right-enter-active,
// .slide-right-leave-active,
// .slide-left-enter-active,
// .slide-left-leave-active {
// transition: all 0.2s linear;
// }
// .slide-right-enter {
// transform: translateX(100%);
// opacity: 1;
// }
// .slide-right-leave-to {
// transform: translateX(-100%);
// opacity: 0;
// }
// .slide-left-enter {
// transform: translateX(-100%);
// opacity: 0;
// }
// .slide-left-leave-to {
// transform: translateX(100%);
// opacity: 1;
// }
// ======
// .slide-right-enter {
// transform: rotateY(-90deg);
// transform-origin: top right;
// }
// .slide-right-leave-to {
// transform: rotateY(90deg);
// transform-origin: top right;
// }
// .slide-left-enter {
// transform: rotateY(-90deg);
// transform-origin: top left;
// }
// .slide-left-leave-to {
// transform: rotateY(90deg);
// transform-origin: top left;
// }
// .slide-enter-active,
// .slide-leave-active {
// transition: opacity 0.5s;
// }
// .slide-enter,
// .slide-leave-to {
// opacity: 0;
// }
// ====
// .slide-right-enter-active,
// .slide-left-leave-active {
// animation: fade 0.6s;
// }
// .slide-right-enter,
// .slide-left-leave-to {
// transform: translateX(100%);
// opacity: 0;
// }
// @keyframes fade {
// from {
// transform: translateX(100%);
// opacity: 0;
// }
// to {
// transform: translateX(0);
// opacity: 1;
// }
// }
.nested-enter-active,
.nested-leave-active {
transition: all 0.3s ease-in-out;
}
.nested-leave-active {
transition-delay: 0.25s;
}
.nested-enter-from,
.nested-leave-to {
transform: translateY(30px);
opacity: 0;
}
.nested-enter-active,
.nested-leave-active {
transition: all 0.3s ease-in-out;
}
.nested-enter-active {
transition-delay: 0.25s;
}
.nested-enter-from,
.nested-leave-to {
transform: translateX(30px);
opacity: 0.001;
}
参考