简体   繁体   English

如何使用jQuery影响同一类的8个div的单个div?

[英]How can I affect a single div of 8 divs of a same class with jQuery?

I should make it work like this 我应该这样工作

Hi everybody. 大家好。 On the first image you can see my task. 在第一张图片上,您可以看到我的任务。 Only the hovered div should change classes of the elements inside, but what I've done is that when you hover any of divs all of them make those changes 只有悬停的div应该更改内部元素的类,但是我所做的是,当您将任何div悬停时,所有这些div都会进行这些更改

$('.industry__item').hover(function () {
    $('.industry__overlay').fadeToggle('active');
    $('.industry__item-text').toggleClass('active');
    $('.industry__item-text p').toggleClass('active');
});

I need a single div to change when person hovers the certain div, but I want to do it in correct way(I know I can add a special class to each div, but that's kinda wrong and not professionally). 当人将鼠标悬停在某个div上时,我需要一个div进行更改,但是我想以正确的方式进行操作(我知道我可以为每个div添加一个特殊的类,但这有点不妥,不是专业的)。 I'm not really good with pure JS but I would appreciate any help and info. 我对纯JS不太满意,但是希望获得任何帮助和信息。 At least I would know what to google. 至少我会知道谷歌。 thank you 谢谢

Well if all the elements are inside that hovered div , try to use $(this) to change the elements of that hovered div like 好吧,如果所有元素都在该div ,请尝试使用$(this)更改该div的元素,例如

$('.industry__item').hover(function() {
  $(this).find('.industry__overlay').fadeToggle('active');
  $(this).find('.industry__item-text').toggleClass('active');
  $(this).find('.industry__item-text p').toggleClass('active');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM