简体   繁体   English

如何 select 一个元素已经在 hover state 与 ZD223E1439188E478329D52?

[英]How to select an element that already has an on hover state with jquery?

I want to add css styles with jquery to an element when another element is hover, the problem is this other element has a css hover effect already, how can i target this already hovered element with jquery? I want to add css styles with jquery to an element when another element is hover, the problem is this other element has a css hover effect already, how can i target this already hovered element with jquery? Is a gallery of images that has an overlay color on hover, what i want to do is to add an opacity effect to a h3 tag when the gallery image is hover.是在 hover 上具有叠加颜色的图像库,我想要做的是在库图像为 hover 时为 h3 标签添加不透明效果。 This is the link: estudiodecimal.com/proyectos/ Here is some code i tried这是链接:estudiodecimal.com/proyectos/ 这是我试过的一些代码

$(".et_pb_gallery_image img").on('hover', function() {
        $("h3.et_pb_gallery_title").css("opacity", 1);
    });

You are not targeting the h3 correctly.您没有正确定位 h3。 Since both the H3 and the img share a common parent, you can find the h3 through closest() and find() , like this.由于 H3 和 img 共享一个共同的父级,因此您可以通过closest()find()找到 h3,如下所示。 I added in a fadeIn and fadeOut rather than a show/hide.我添加了一个淡入淡出和淡出而不是显示/隐藏。

 $(".et_pb_gallery_image img").hover(imgHover, imgHover) function imgHover(e) { let o = $(this).closest('.et_pb_gallery_item').find("h3"); if (e.type == 'mouseenter') o.fadeIn(); else o.fadeOut() }
 h3 { display: none; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class='et_pb_gallery_item'> <div class='et_pb_gallery_image'> <img src='https://picsum.photos/200/300' /> </div> <h3>Title</h3> </div>

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

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