Answer the question
In order to leave comments, you need to log in
How to add a class only to the element that is hovered over with the mouse?
Hello. How to implement a functionality where there are identical blocks with the same classes, but when hovering over the button, the class should be added only to the block where the button was hovered over? The code itself:
<div class="col-md-3 services-item" :class="{'hoverClass': active_services}">
<img src="img/laptop.png" alt="">
<h3 class="my_services_title">Тест</h3>
<button class="btn-price" @mouseenter="active_service()" @mouseleave="deactive_service()">Нажать</button>
</div>
<div class="col-md-3 services-item" :class="{'hoverClass': active_services}">
<img src="img/laptop.png" alt="">
<h3 class="my_services_title">Тест</h3>
<button class="btn-price" @mouseenter="active_service()" @mouseleave="deactive_service()">Нажать</button>
</div>
var body = new Vue({
el:'#main',
data:{
active_services: false
},
methods:{
active_service: function(){
this.active_services = true;
},
deactive_service:function(){
this.active_services = false;
}
}
});
Answer the question
In order to leave comments, you need to log in
<div
v-for="item in items"
class="col-md-3 services-item"
:class="{ hoverClass: item.hover }"
>
<img :src="item.scr" alt="">
<h3 class="my_services_title">Тест</h3>
<button
class="btn-price"
@mouseenter="item.hover = true"
@mouseleave="item.hover = false"
>Нажать</button>
</div>
data: {
items: [
{
src: 'img/laptop.png',
hover: false,
},
{
src: 'img/laptop.png',
hover: false,
},
],
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question