在行/单元格之间调用表的Onmouseout函数
Onmouseout function for table gets called between rows/cells
我有一个onmouseover函数的图像,该函数会在图像上显示一个带有一些选项的表(图像变暗)。表格有一个onmouseout函数,它应该隐藏表格并再次显示图像。我遇到的问题是,每当鼠标移动到行或单元格之间,甚至在单元格内的链接上,表格就会闪烁,就好像鼠标离开了表格一样。我该如何解决这个问题?
JSFiddle
<script type="text/javascript">
function dimImg(x) {
x.style.opacity = "0.3";
document.getElementById("happinessItems").style.visibility = 'visible';
}
function normalImg(x) {
document.getElementById('firstImg').style.opacity = "1.0";
x.style.visibility = 'hidden';
}
</script>
<style type="text/css">
table{
position: absolute;
top: 0px;
width: 495px;
height: 330px;
visibility: hidden;
border-collapse: collapse;
border-spacing: 0px;
}
table td {
width: 247.5px;
text-align: center;
}
</style>
<a href="happiness.php"><img id="firstImg" onmouseover="dimImg(this)" src="img/leftButton.jpg" style="display:inline-block; width:495px; margin-right:5px; -webkit-filter: drop-shadow(5px 5px 5px #222); filter: drop-shadow(5px 5px 5px #222)" /></a>
<table cellspacing="0" id="happinessItems" onmouseout="normalImg(this)">
<tr><td><a href="#">Coats/Jackets</a></td><td><a href="#">Sweaters/Hoodies</a></td></tr>
<tr><td><a href="#">Dresses/Suits</a></td><td><a href="#">Tshirts/Tops</a></td></tr>
<tr><td><a href="#">Shoes</a></td><td><a href="#">Bags</a></td></tr>
<tr><td colspan="2"><a href="#">Accessories</a></td></tr>
</table>
如果有人需要使用JavaScript的答案,对我来说有效的是使用onmouseenter
和onmouseleave
而不是onmouseover
和onmouseout
。
onmouseenter
和onmouseleave
没有气泡,所以当你将鼠标悬停在孩子们的上方时,它们不会给你闪烁的效果。
您希望它是这样工作的吗?
http://jsfiddle.net/9s89bL3u/2/只有css和html。
.test2 {
position: relative;
width: 495;
height: 330px;
background-color: blue;
}
.test1:hover table{
visibility: visible;
}
.test1:hover .test2{
opacity: 0.3;
}
table {
position: absolute;
top: 0px;
width: 495px;
height: 330px;
border-collapse: collapse;
visibility: hidden;
border-spacing: 0px;
}
table td {
width: 247.5px;
text-align: center;
}
请记住两件重要的事情:
<!doctype html> //at the very top of the page
border="0" cellspacing="0" cellpadding="0" //inside your table tag
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 如何在JavaScript中将字符串转换为函数引用
- 用嵌套函数和默认函数定义函数
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- JQuery合并了keyup和focusout两个函数
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 我可以在json对象中添加一个函数吗
- AngularJS:我可以跳过函数参数回调吗
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- onmouseout函数工作不正常
- 我无法使onmouseout函数工作
- jQuery - 调用函数onmouseout,但仅当光标未移动到某个区域时
- 在 onMouseOut 上调用 javascript 函数
- 在行/单元格之间调用表的Onmouseout函数
- 用javascript动态创建onmouseover/onmouseout函数