<!DOCTYPE html>
<html>
<head>
<title>vue中的js动画与velocity.js的结合</title>
<script src="./vue.js"></script>
<script src="./velocity.min.js"></script>
</head>
<body>
<div id='app'>
<!-- 使用js钩子函数 -->
<transition
name="fade"
@before-enter="handleBeforeEnter"
@enter="handEnter"
@after-enter="handleAfterEnter">
<div v-if="show">hello world</div>
</transition>
<button @click='handleClick'>切换</button>
</div>
<script>
var vm1 = new Vue({
el: '#app',
data: {
show: true
},
methods: {
handleClick: function() {
this.show = !this.show
},
handleBeforeEnter: function(el) {
el.style.opacity = 0;
},
handEnter: function(el,done) {
Velocity(el,{
opacity: 1},{
duration: 1000,
complete: done})
},
handleAfterEnter: function(el) {
console.log('动画结束')
}
}
})
</script>
</body>
</html>
网友评论