<template>
<div class="main">
<button @click="data = !data">change</button>
<div class="container">
<transition name="fade">
<div :key="data">{{ data }}</div>
</transition>
</div>
</div>
</template>
<script>
export default {
name: "test-vue",
data() {
return {
data: false,
};
},
};
</script>
<style lang="css">
.main {
display: flex;
flex-direction: column;
align-items: center;
}
.container {
width: 100px;
text-align: center;
position: relative;
}
.container > * {
position: absolute;
text-align: center;
width: 100%;
}
.fade-enter {
margin-left: 100%;
}
.fade-enter-to {
margin-left: 0%;
}
.fade-leave-active,
.fade-enter-active {
transition: margin-left 1s;
}
.fade-leave-to {
margin-left: -100%;
}
</style>