我试图创建一个Vue组件,当鼠标光标悬停在该组件上时,该组件会反弹。我正在使用animate.css库,用@mouseover更改组件类,然后在@mouseout上重置它。
有什么优雅的方法(或Vue方法)可以解决这个问题吗?
这是我的密码:
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.min.css">
</head>
<body>
<div id="app">
<h1>Hover the mouse near the border</h1>
<hr>
<button :class="classes"
@mouseover="hoverOver"
@mouseout="hoverOut"
>
IMMEDIATE
</button>
<br><br><br>
<button :class="classes"
@mouseover="hoverOver"
@mouseout="hoverOutTimeout"
>
WAIT JUST A BIT
</button>
</div>
</body>
Javascript:
new Vue({
el: "#app",
data: {
classes: []
},
methods: {
hoverOver: function() {
console.log('over');
this.classes = ['animated', 'bounceIn']
},
hoverOut: function() {
console.log('out');
this.classes = []
},
hoverOutTimeout: function() {
setTimeout(() => {
console.log('out');
this.classes = []
}, 1000);
},
}
})
https://jsfiddle.net/marcellorvalle/eywraw8t/477611/