JavaScript钩子
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>javascript钩子(使用Velocity)</title>
<script src="https://unpkg.com/vue"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/1.2.3/velocity.min.js"></script>
</head>
<body>
<div id = "demo">
<button @click = "show = !show">click me</button>
<transition
v-on:before-enter="beforeEnter"
v-on:enter="enter"
v-on:leave="leave"
v-bind:css="false"
>
<p v-if="show">ling</p>
</transition>
</div>
<script>
var vm = new Vue({
el:'#demo',
data:{
show:false
},
methods:{
beforeEnter: function (el) {
el.style.opacity = 0;
el.style.transformOrigin = 'left'
},
enter: function (el, done) {
Velocity(el, { opacity: 1, fontSize: '3em' }, { duration: 300 })
Velocity(el, { fontSize: '1em' }, { complete: done })
},
leave: function (el, done) {
Velocity(el, { translateX: '15px', rotateZ: '50deg' }, { duration: 600 })
Velocity(el, { rotateZ: '100deg' }, { loop: 2 })
Velocity(el, {
rotateZ: '45deg',
translateY: '100px',
translateX: '100px',
opacity: 0
}, { complete: done })
}
}
})
</script>
</body>
</html>
效果图
参考文档
Vue.js文档
Velocity.js 中文文档