简体   繁体   English

CSS / JQuery:如何为表格行创建子菜单,使子菜单从行到菜单始终保持可见状态?

[英]CSS/JQuery: how to create submenu for table row that stays visible mousing from row onto menu?

I'm a CSS/JQuery rookie, but have built several things with the basics. 我是CSS / JQuery新手,但是已经用基础构建了几件事。 Just need some general direction. 只需要一些一般的方向。

I have an HTML table (I'm forced to use a table w/ tabular data in this situation) and need to, on hover of a row: 1) draw a line around the row to highlight it, and 2) hook a little dropdown menu to the bottom of the cell that I'm hovering. 我有一个HTML表格(在这种情况下,我不得不使用带有表格数据的表格),并且需要将鼠标悬停在一行上:1)在该行周围画一条线以突出显示它,以及2)稍微勾一下悬停的单元格底部的下拉菜单。

My question is: if the menu gets triggered on hover of the row, but you mouse down over the menu, how do you keep the row highlighted and the menu active until you mouse off the menu? 我的问题是:如果菜单是在该行的悬停上触发的,但是您将鼠标悬停在菜单上,如何保持该行处于突出显示状态并且该菜单处于活动状态,直到您将鼠标从菜单上移开? I assume the row highlighting and menu itself would disappear when mousing off the row. 我认为当鼠标移出该行时,该行的突出显示和菜单本身将消失。

For the life of me, I can't find an example of this. 对于我的一生,我找不到这样的例子。

On the tr 's mouseenter event, assign the row a class of "highlighted" and display your menu. trmouseenter事件上,为该行分配“突出显示”类,并显示菜单。

On the menu's mouseleave event hide the menu and remove the "highlighted" class from any row which has it. 在菜单的mouseleave事件上,隐藏菜单,并从具有菜单的任何行中删除“突出显示”的类。

Something like : 就像是 :

var $myMenu = $('#myMenu');

$('tr').mouseenter(function(){
    $this = $(this);
    $this.addClass('highlighted');
    $myMenu.appendTo($this).slideDown();
});

$myMenu.mouseleave(function(){
    $(this).slideUp();
    $('tr.highlighted').removeClass('highlighted');
});

Try a simple drop down like this one but from a cell. 这样尝试一个简单的下拉列表,但是从单元格中进行。 For the highlights assign a border of the same colour of the cell, then on hover change the border colour. 为高光指定与单元格相同颜色的边框,然后在悬停时更改边框颜色。

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

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