简体   繁体   English

将鼠标悬停在表中的特定元素上时,如何不对表行触发悬停效果

[英]How to NOT trigger hover effect on table row when hovering over specific element inside it

I have hover effect on table row. 我对表格行有悬停效果。 And inside the table there is a popover menu that appears. 表格内部会出现一个弹出菜单。 The problem is when hovering over popover menu it's table row hover effect gets triggered (as in attached picture). 问题是,将鼠标悬停在弹出菜单上时会触发表行悬停效果(如附图所示)。 The question is how to not trigger hover effect over table row when hovering over popover? 问题是,将鼠标悬停在弹出框上时如何不触发表行的悬停效果?

Image of the effect 效果图

I attached also the markup below. 我还附上了下面的标记。

<table class="table__table">
<tbody>
    <tr class="table__body__tr">
        <td class="table__body__td">Comment</td>
        <td class="table__body__td">
            <button type="button" class="three-dots"></button>
            <div class="popover__menu is-opened">
                <a href="#" class="popover__link">Reply to comment</a>
                <a href="#" class="popover__link">Delete comment</a>
            </div>
        </td>
    </tr>
</tbody>

CSS 的CSS

.table {
    &__body {
        &__tr {
            transition: background-color .1s;

            &:hover {
                background-color: $grey--light;
            }
        }
    }
}

.popover {
    &__menu {
        position: absolute;
        left: 0;
        visibility: hidden;
        opacity: 0;
        z-index: -1;

        width: auto;

        background-color: white;

        &.is-opened {
            z-index: 1;
            visibility: visible;
            opacity: 1;
        }
    }
}  

Two simple quick methods i can think of is 我能想到的两个简单的快速方法是

add an id to your row as such <tr data-row_id='1'> and then do the same over on your popup element <div data-row_id='1'> and then apply a function on your on hover the popup to simply add a class to tr with the same data row id to hide the tr hover effect. 将id添加到您的行中,例如<tr data-row_id='1'> ,然后在弹出元素<div data-row_id='1'> ,然后将鼠标悬停在弹出<div data-row_id='1'>上只需将具有相同数据行ID的类添加到tr中即可隐藏tr悬停效果。

https://api.jquery.com/data/ https://api.jquery.com/data/

Or write another jquery function to simply find the parent row and again apply a class on hover of the popup. 或编写另一个jquery函数以简单地找到父行,然后在弹出窗口的悬停上再次应用一个类。 You can use closest() method for that 您可以为此使用mostest()方法

https://api.jquery.com/closest/ https://api.jquery.com/closest/

If you post your jquery code or if you are using plain javascript just post it here to help you further 如果您发布自己的jquery代码,或者您使用的是纯JavaScript,请将其发布在此处以帮助您进一步

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

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