我有一张显示信息的表格。表中的一列是注释列。在本笔记栏中,我使用了一些CSS和Jquery创建了一个工具提示。我遇到的问题是,当我将鼠标悬停在单元格上时,它会正确显示工具提示,但是在将鼠标移开后,它会从单元格中擦除颜色(变成白色)。我希望它在鼠标移开后保留其颜色,但我不确定如何。
工具提示事件的当前代码(每个备注单元格都有备注类):
$('.note').hover(
function (event) {
$(event.target).css({
"white-space": "normal",
"text-overflow": "clip",
"background-color": "#eeeeee",
"max-width": "200px",
"position": "absolute"
});
}, function (event) {
$(event.target).css({
"white-space": "nowrap",
"text-overflow": "ellipsis",
"background-color": "transparent",
"max-width": "200px",
"position": "static"
});
}
);
答案 0 :(得分:1)
为此目的,最好使用纯css
,
.note:hover {
white-space: normal;
text-overflow: clip;
background-color: #eeeeee;
max-width: 200px;
position: absolute;
}
在这种情况下,元素将在悬停后保留背景颜色和其他属性。