程序有问题,一直输入动画结束,除了第一次动画正确,但是一次动画开始也没有
来源:5-4 Vue中的 Js 动画与 Velocity.js 的结合
迷失的小麦
2020-04-29
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue中的JS动画与velocity.js</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<transition
name="fade"
@before-enter="handleBeforeEnter"
@enter="handleEnter"
@after-enter="handleAfterEnter"
@before-leave="handleBeforeLeave"
@leave="handleLeave"
@after-leave="handleAfterLeave"
>
<div v-if="show">Hello World</div>
</transition>
<button @click="handleClick">toggle</button>
</div>
<script>
var vm = new Vue({
el: "#root",
data: {
show: true
},
methods: {
handleClick: function() {
this.show = !this.show
},
handleBeforeEnter: function(el) {
el.style.opacity = 0;
},
handleEnter: function(el, done) {
el.style.opacity=1;
el.style.transition='opacity 5s ease';
el.ontransitionEnd=function(){
done();
};
},
handleAfterEnter: function(el) {
console.log("动画开始")
},
handleBeforeLeave: function(el) {
el.style.opacity = 1;
},
handleLeave: function(el, done) {
el.style.opacity=0;
el.style.transition='opacity 5s ease';
el.ontransitionEnd=function(){
done();
};
},
handleAfterLeave: function(el) {
console.log("动画结束")
}
}
})
</script>
</body>
</html>
写回答
2回答
-
Dell
2020-05-03
同学你是想搞一个appear的效果吗
00 -
呀呀呀亚歌
2020-04-29
为什么我复制你的代码,代码的动画在点击按钮的时候,能够正常转换啊?
012020-04-30
相似问题