<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue中的JS动画</title>
<script src="js/vue.js"></script>
<script src="js/velocity.js"></script>
</head>
<body>
<div id="app">
<transition
name="fade"
@before-enter="handleBeforeEnter"
@enter="handleEnter"
@after-enter="handleAfterEnter">
<div v-show="seen">hello world</div>
</transition>
<button @click="handleClick">切换</button>
</div>
<script>
new Vue({
el:'#app',
data:{
seen:true
},
methods:{
handleClick:function () {
this.seen=!this.seen
},
handleBeforeEnter:function (el) {
console.log("ss")
el.style.color='red'
},
handleEnter:function (el,done) {
setTimeout(()=>{
el.style.color='blue'
},2000)
setTimeout(() => {
done()
},4000)
},
handleAfterEnter:function (el) {
el.style.color='#000'
}
}
})
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Velocity.js的结合</title>
<script src="js/vue.js"></script>
<script src="js/velocity.js"></script>
</head>
<body>
<div id="app">
<transition
name="fade"
@before-enter="handleBeforeEnter"
@enter="handleEnter"
@after-enter="handleAfterEnter">
<div v-show="show">hello world</div>
</transition>
<button @click="handleClick">切换</button>
</div>
<script>
new Vue({
el:'#app',
data:{
show:true
},
methods:{
handleClick:function () {
this.show=!this.show
},
handleBeforeEnter:function (el) {
el.style.opacity=0;
},
handleEnter:function (el,done) {
Velocity(el,{opacity:1}
,{duration:1000,complete:done})
},
handleAfterEnter:function (el) {
alert("结束动画")
}
}
})
</script>
</body>
</html>