<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue中的Js动画与velocity.js结合</title>
<script src="https://unpkg.com/vue@2.5.16/dist/vue.js"></script>
</head>
<body>
<div id="app">
<!-- 以下是入场动画的使用,出厂动画将所有的enter变为leave -->
<transition
name="fade"
@before-enter="handleBeforeEnter"
@enter = "handleEnter"
@after-enter = "handleAfterEnter"
>
<div v-show="show">hello world</div>
</transition>
<button @click="handleChange">显示与隐藏</button>
</div>
<script>
var vm = new Vue({
el : "#app",
data : {
show : true
},
methods : {
handleChange : function(){
this.show = !this.show
},
// 显示时触发
handleBeforeEnter : function(el){
console.log("beforeEnter");
el.style.color = "red";
},
// before-enter触发之后,真正的运行动画了,就执行
handleEnter : function(el,done){
setTimeout(function(){
el.style.color = "green";
// 告诉动画执行完了。
// done();
},1000)
setTimeout(function(){
done();
},2000)
},
handleAfterEnter : function(el){
el.style.color = "black";
}
}
})
</script>
</body>
</html>
网友评论