Answer the question
In order to leave comments, you need to log in
Trigger an animation when the mouse is held down on an element for at least 1 sec VUE?
Good afternoon
Tell me how to write a timer correctly so that the menu opens when you hover and hold the mouse on the menu item for at least 1 second
Now like this:
<div class="nav-catalog" @mouseleave="hoverOut">
<ul>
<li class="nav-catalog__menu__item"
v-for="(item,index) of menu"
:class="{ active: current == index }"
:data-menu="index"
@mouseenter="hoverOver(index)">
<a :href="item.url">{{item.t}}</a>
</li>
</ul>
<transition name="fade" mode="out-in">
<div v-if="show" class="nav-catalog__submenu">
<ul v-for="(item,index) of showMenu">
<li class="first">
<a :href="item.url">
{{item.t}}
</a>
</li>
</ul>
</div>
</transition>
</div>
let subMenu = new Vue({
el: '.nav-catalog',
data: {
show: false,
timerId: 0,
current: null
},
methods: {
hoverOver(index) {
this.timerId = setTimeout(() => {
this.showMenu = this.subMenu[index]
this.show = true
this.current = index
}, 1000);
},
hoverOut() {
clearTimeout(this.timerId)
this.timerId = 0
this.show = false
this.current = null
},
}
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question