请问为什么显示的是从红到绿 但是最后动画执行完毕文字又编程黑色了
来源:2-3 使用 transition 标签实现单元素组件的过渡和动画效果(2)
weixin_慕村1291783
2020-12-25 22:38:50
# 具体遇到的问题
# 报错信息的截图
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/vue@next"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
<style>
@keyframes leftMove {
0% {
transform: translateX(-100px);
}
50% {
transform: translateX(50px);
}
100% {
transform: translateX(0px);
}
}
/* .donghua {
animation: leftMove 3s;
} */
/* .guodu {
transition: background-color 3s ease;
}
.blue {
background-color: skyblue;
}
.pink {
background-color: pink;
} */
.v-enter-from {
color: red;
}
.v-enter-active {
animation: leftMove 3s;
transition: color 3s;
}
.v-enter-to {
color: green;
}
/* .v-leave-from {
opacity: 1;
} */
.v-leave-active {
animation: leftMove 3s;
transition: color 4s;
}
.v-leave-to {
color: red;
}
</style>
</head>
<body>
<div id="root"></div>
</body>
<script>
const app = Vue.createApp({
data() {
return {
show: false
}
},
methods: {
handleChange() {
this.show = !this.show;
}
},
template: `
<transition>
<div v-if="show">hello world</div>
</transition>
<button @click="handleChange">切换</button>
`
})
const vm = app.mount('#root')
</script>
</html>
1回答
樱桃小胖子
2020-12-26
同学你好,v-enter-to表示元素过渡动画终点的样式,过渡动画结束后会把它和v-enter-active直接删除,因为class类被删除,就找不到样式了,所以会变成默认的黑色。如下:
祝学习愉快!
相似问题