I would like to show a div when hovering over an element in vue.js. But I can't seem to get it working.
It looks like there is no event for hover or mouseover in vue.js. Is this really true?
Would it be possible to combine jquery hover and vue methods?
There's no need for a method here.
HTML
JS
With
mouseover
only the element stays visible when mouse leaves the hovered element, so I added this:@mouseover="active = !active" @mouseout="active = !active"
Here is a working example of what I think you are asking for.
http://jsfiddle.net/1cekfnqw/3017/
Please take a look at the vue-mouseover package if you are not satisfied how does this code look:
vue-mouseover provides a
v-mouseover
directive that automaticaly updates the specified data context property when the cursor enters or leaves an HTML element the directive is attached to.By default in the next example
isMouseover
property will betrue
when the cursor is over an HTML element andfalse
otherwise:Also by default
isMouseover
will be initially assigned whenv-mouseover
is attached to thediv
element, so it will not remain unassigned before the firstmouseenter
/mouseleave
event.You can specify custom values via
v-mouseover-value
directive:or
Custom default values can be passed to the package via options object during setup.
To show child or sibling elements it's possible with CSS only. If you use
:hover
before combinators (+
,~
,>
,space
). Then the style applies not to hovered element.HTML
CSS