在工具提示中将鼠标悬停时更改背景颜色
change background color on mouse over in tooltip
当我将鼠标悬停在表格中的行上时,将显示图像,当鼠标悬停在图像上时,会显示工具提示。当我将鼠标悬停在工具提示中的选项(即test1,test2)上时,放置鼠标光标的选项应突出显示或更改其背景颜色,以让用户知道他们即将单击工具提示中的哪个选项。请找到小提琴 http://jsfiddle.net/0w9yo8x6/65/
下面是示例 JavaScript 代码:
$(function() {
var rowData;
$(document).tooltip({
items: "img, [data-title]",
content: function () {
var element = $(this);
if (element.is("img"))
{
rowdata = element.attr("data-title");
$(document).off('click', '#test');
$(document).on('click', '#test', function() {
test();
});
}
return $(this).prop('title');
},
show: null,
close: function (event, ui) {
ui.tooltip.hover(
function () {
$(this).stop(true).fadeTo(1000, 1);
},
function () {
$(this).stop(true).fadeOut(200, function () {
$(this).remove();
})
});
},
position: {
my: "left",
at: "right"
}
});
});
$(function () {
$('.one').attr('title', $('.myTooltipTable').remove().html());
$(document).tooltip();
});
我认为这就是你要找的:http://jsfiddle.net/0w9yo8x6/66/
您必须注意何时使用 ID 以及何时使用类。
.toolTipHover:hover {
background-color:lightgray;
}
<table class="myTooltipTable" style="position:absolute;">
<tr><td> <span id="test" class="toolTipHover">test1</span></td></tr>
<tr><td> <span id="test" class="toolTipHover">test2</span></td></tr>
</table>
在上面的 HTML 中,您会看到 id="test" 有两个不同的东西?其中只有一个应该注册(第一个),因为在 DOM 上,id 必须是唯一的。所以我实现了一个类工具TipHover并将css应用于该类。
我没有接触任何其他代码,但我建议回顾一下您的代码以确保 id 是唯一的,并且如果您希望应用相同函数的多个元素,也许添加一个类将是最佳选择。
您无需编辑 HTML 并添加其他类。您可以通过添加一个简单的CSS
悬停效果来实现这一点:
您只需要添加以下代码:
.ui-tooltip-content span:hover {
background-color:Orange;
transition:all 0.4s ease-in-out;
}
请参阅下面的完整代码:
$(function() {
var rowData;
$(document).tooltip({
items: "img, [data-title]",
content: function () {
var element = $(this);
if (element.is("img"))
{
rowdata = element.attr("data-title");
$(document).off('click', '#test');
$(document).on('click', '#test', function() {
test();
});
}
return $(this).prop('title');
},
show: null,
close: function (event, ui) {
ui.tooltip.hover(
function () {
$(this).stop(true).fadeTo(1000, 1);
},
function () {
$(this).stop(true).fadeOut(200, function () {
$(this).remove();
})
});
},
position: {
my: "left",
at: "right"
}
});
});
$(function () {
$('.one').attr('title', $('.myTooltipTable').remove().html());
$(document).tooltip();
});
td.myData > img {
display: none;
float:right;
height: 19px;
}
td.myData:hover > img {
display: inline-block;
}
.ui-tooltip-content span {
transition:all 0.4s ease-in-out;
}
.ui-tooltip-content span:hover {
background-color:Orange;
transition:all 0.4s ease-in-out;
}
<script>
function test(){
alert("test invoked");
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
<table class="myTooltipTable" style="position:absolute;">
<tr><td> <span id="test" >test1</span></td></tr>
<tr><td> <span id="test" >test2</span></td></tr>
</table>
<br/><br><br>
<table border="1">
<tr>
<td class="myData">Data1 <img class="one" id="one" data-title="Data1" src="http://ssl.gstatic.com/gb/images/b_5dae6e31.png" width="15" height="15" alt="" />
<img class="two" id="two" src="https://www.webkit.org/blog-files/acid3-100.png" width="15" height="15" style="visibility:hidden;"/>
</td>
</tr>
<tr>
<td class="myData">Data2 <img class="one" id="one" data-title="Data2" src="http://ssl.gstatic.com/gb/images/b_5dae6e31.png" width="15" height="15" alt="" />
<img class="two" id="two" src="https://www.webkit.org/blog-files/acid3-100.png" width="15" height="15" style="visibility:hidden;"/>
</td>
</tr>
<tr>
<td class="myData">Data3 <img class="one" id="one" data-title="Data3" src="http://ssl.gstatic.com/gb/images/b_5dae6e31.png" width="15" height="15" alt="" />
<img class="two" id="two" src="https://www.webkit.org/blog-files/acid3-100.png" width="15" height="15" style="visibility:hidden;"/>
</td>
</tr>
</table>
相关文章:
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何使用jquery更改html中的背景颜色
- Javascript对象类在单击时打开窗口进行颜色选择,并在更改时替换对象背景颜色
- JS幻灯片与CSS背景颜色变化
- DT数据表背景颜色为黑色,但仍有悬停和选择颜色
- Javascript通过列表项的函数和css来更改背景颜色
- Javascript没有从数组中选择背景颜色
- 使用圆中的数组更改背景颜色项目
- 如何用jquery动画改变背景颜色,就像一个过渡
- 使用jquery交换并保存背景颜色
- j查询如何设置/取消设置下拉菜单的背景颜色
- 使用angularjs根据时间更改背景颜色
- 设置Dojo量表的背景颜色
- javascript样式的背景颜色在设置时闪烁.ASP.NET
- 使用javascript更改任意文本的背景颜色
- 在用Javascript更改背景颜色后:hover don'不要改变颜色
- 图像内部的透明背景颜色不受影响
- jQuery mobile-动态更改ui页面背景颜色
- 切换按钮的背景颜色
- JavaScript更改类的背景颜色