简体   繁体   English

如何使jQuery将其他元素包含在悬停中

[英]How can I make jQuery to include other Elements into hover

i have a little problem concerning hover and jQuery: 我有一个关于悬停和jQuery的小问题:

I have created a table out of a mySQL-Database. 我已经从mySQL数据库创建了一个表。 There are some specific rows, that geht the Attribute display:none in order to not show them. 有一些特定的行在“属性”显示中:none,以便不显示它们。 But if you lay down the mous on the element obove the invisible one, the invisible element should become visible (maybe, there are more than one invisible elements, than all the invisible elements up to the next visible element should became visible. If you get the mouse off these elements, the invisible ones should disappear again. I have made a function, which does exactly what I want, exept one little thing. I would like to refer the hover not only to the visible row, but also to the invisible, which means, if you get the mouse off the visible element, to the former invisible elements, they aren't supposed to disappear, but they do! I have tried to organize the tr's with spans, but it seems at HTML don't like spans in tables, unless they aren't in td's. After that I have tried to solve the problem with the tr an mouse position, and bind the mousemove to all elements. This doesn't work either (In the following example I tried at first the xy-position of the visible Element itself, if 但是,如果您将慕斯放到隐藏不可见元素的元素上,则不可见元素应该变得可见(也许,不可见元素不止一个,超过下一个可见元素的所有不可见元素都应该变得可见。鼠标移开这些元素后,不可见的元素应该会再次消失。我做了一个功能,正是我想要的,只做了一件小事,我不仅要将悬停引用到可见行,还要引用不可见的行,这意味着,如果将鼠标从可见元素移到以前的不可见元素,它们不应该消失,但是它们会消失!我试图用跨度组织tr,但在HTML上似乎不就像表中的跨度一样,除非它们不在td中。在那之后,我尝试用鼠标位置tr来解决问题,并将mousemove绑定到所有元素。这也不起作用(在下面的示例中,我尝试了首先,如果可见元素本身的xy位置 i get this work, i will expand it to the former invisible elements. 我得到了这项工作,我会将其扩展到以前的隐形元素。

$("#NH00").hover(
    function(){
        $('tr[name="hiddenNH00"]').show();},
    function(){
        $("*").one("mousemove", function(e) {
            var offset = $(this).offset();
            var xlt = offset.left;
            var ylt = offset.top;
            var xrb = offset.left + $(this).outerWidth(false);
            var yrb = offset.top + $(this).outerHeight(false);
            if(e.pageX < xlt || e.pageX > xrb || e.pageY < ylt || e.pageY > yrb){
                $('tr[name="hiddenNH00"]').hide();
            }
        })
    }
);

Take a look at the jExpand plugin . 看一下jExpand插件
The only possible issue I see is that it seems to expect for there to be one visible row, and one hidden row rather than multiples, as you describe. 我看到的唯一可能的问题是,它似乎期望有一个可见行和一个隐藏行,而不是您所描述的倍数。

If that is a problem, maybe you can re-work your markup so that the visible row is the same as now, but the hidden ones are in a nested table in the secondary row. 如果这一个问题,也许您可​​以重新进行标记,以使可见行与现在相同,但隐藏行位于第二行的嵌套表中。

Make sure you read through the comments. 确保您已阅读所有注释。 Apparently there was an IE8 issue that someone fixed, and I'm not sure it made it back into the actual documentation. 显然有人解决了IE8的问题,但我不确定它是否会重新出现在实际的文档中。

Why not attach the same event handler to the "invisible" rows? 为什么不将同一事件处理程序附加到“不可见”行?

$("#NH00, tr[name='hiddenNH00']").hover(
    function(){
        $('tr[name="hiddenNH00"]').show();
    },
    function(){
        $('tr[name="hiddenNH00"]').hide();
    }
);

DEMO 演示

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

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