onmouseover事件不起作用
onmouseover event not working
我制作了一个简单的hud,当你的鼠标在主面板上时,它会显示出来。由于某种原因,房子里到处都是不工作的。当我在面板上的浏览器中单击inspect元素时,它会显示html标记。我知道侦听器是创建的,同样是通过查看浏览器中的inspect元素。
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<LINK href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="mainpanel" class="notselectable">
<div id="top">
<img src="icons/white/open.png" style="float:right" class="btnMedia" />
</div>
<div id="bottom">
<center>
<img src="icons/white/pre.png" class="leftandright btnMedia" />
<img src="icons/white/play.png" class="leftandright btnMedia" />
<img src="icons/white/next.png" class="leftandright btnMedia" />
</center>
</div>
</div>
</body>
<script>
var panel = document.getElementById("mainpanel");
var top = document.getElementById("top");
var bottom = document.getElementById("bottom");
//alert("script")
panel.onmouseover = function() {
alert("in")
top.display = "block";
bottom.display = "block";
}
panel.onmouseout = function() {
alert("out")
top.display = "none";
bottom.display = "none";
}
</script>
</html>
您的代码中有两处错误。
- 使用CSS值进行操作时缺少
style
top
是JavaScript中的一个保留关键字,将其用作变量很难
这项工作:
var panel = document.getElementById("mainpanel");
var top2 = document.getElementById("top");
var bottom = document.getElementById("bottom");
panel.onmouseover = function() {
top2.style.display = "block";
bottom.style.display = "block";
}
panel.onmouseout = function() {
top2.style.display = "none";
bottom.style.display = "none";
}
#mainpanel {
background: #faa;
height: 100vh;
}
#top, #bottom {
display: none;
}
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<div id="mainpanel" class="notselectable">
<div id="top">
I am top!
</div>
<div id="bottom">
I am bottom!
</div>
</div>
</body>
</html>
相关文章:
- JsFiddle上的鼠标事件不起作用
- 在IE8中不起作用的元素上触发单击事件
- 链接上的IE10 jquery句柄单击事件不起作用
- Javascript点击事件回调不起作用
- jQuery加载完成事件不起作用
- 覆盖单击事件不起作用
- 鼠标事件在OpenLaszlo应用程序中不起作用
- 单击事件不起作用
- 插入后单击锚点标记上的事件after不起作用
- 为什么body元素上的onclick事件不起作用
- 追加Jquery后的Binding Click事件不起作用
- chrome中的onmouseover(下拉选项标记)事件不起作用-php,javascript
- 添加事件侦听器不起作用
- onclick事件在asp.net上不起作用
- jQuery调用keyup事件不起作用
- 单击事件在jquery easyui多选项卡中不起作用
- jQuery ContextMenu事件在IOS 8.2中不起作用
- 第二个事件[onClick]不起作用
- 按键事件上的简单HTML输入不起作用
- Keyup事件在easyui上不起作用