随鼠标浮动的层,style.left属性赋值问题
2008-05-29 18:39
239 查看
今天需要做一个效果,当鼠标移动到一个图片上时,就显示一段文字介绍。需要用js操纵一个浮动的层。我很快按要求写好了,在IE下浏览一切正常,但是在firefox下却不行。浮动的层,怎么也动不起来。
经过一番查找,终于找到原因:
var o = document.getElementById("hidDiv");
//o.style.left = e.clientX;//这种赋值方法,IE下可以,在firefox下不起作用
//o.style.top = e.clientY;
正确的赋值方法:
o.style.left = e.clientX+"px";
o.style.top = e.clientY+"px";
网页:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script type="text/javascript">
function showDiv(e)
{
var o = document.getElementById("hidDiv");
//o.style.left = e.clientX;//这种赋值方法,IE下可以,在firefox下不起作用
//o.style.top = e.clientY;
o.style.left = e.clientX+"px";
o.style.top = e.clientY+10+"px";
o.style.display="block";
}
</script>
</head>
<body>
<div style="width: 168px; height: 24px; background-color: #ffff66;" onmouseover="showDiv(event)">
</div>
<div style="width: 168px; height: 24px; background-color: #ccff66;" onmouseover="showDiv(event)">
</div>
<div style="width: 168px; height: 24px; background-color: #ffff66;" onmouseover="showDiv(event)">
</div>
<div style="width: 168px; height: 24px; background-color: #ccff66;" onmouseover="showDiv(event)">
</div>
<div style="width: 168px; height: 24px; background-color: #ffff66;" onmouseover="showDiv(event)">
</div>
<div id="hidDiv" style="width: 238px; position: absolute; display: none; height: 120px;left: 228px; top: 22px; background-color: #ffcc33;">
</div>
</body>
</html>
经过一番查找,终于找到原因:
var o = document.getElementById("hidDiv");
//o.style.left = e.clientX;//这种赋值方法,IE下可以,在firefox下不起作用
//o.style.top = e.clientY;
正确的赋值方法:
o.style.left = e.clientX+"px";
o.style.top = e.clientY+"px";
网页:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script type="text/javascript">
function showDiv(e)
{
var o = document.getElementById("hidDiv");
//o.style.left = e.clientX;//这种赋值方法,IE下可以,在firefox下不起作用
//o.style.top = e.clientY;
o.style.left = e.clientX+"px";
o.style.top = e.clientY+10+"px";
o.style.display="block";
}
</script>
</head>
<body>
<div style="width: 168px; height: 24px; background-color: #ffff66;" onmouseover="showDiv(event)">
</div>
<div style="width: 168px; height: 24px; background-color: #ccff66;" onmouseover="showDiv(event)">
</div>
<div style="width: 168px; height: 24px; background-color: #ffff66;" onmouseover="showDiv(event)">
</div>
<div style="width: 168px; height: 24px; background-color: #ccff66;" onmouseover="showDiv(event)">
</div>
<div style="width: 168px; height: 24px; background-color: #ffff66;" onmouseover="showDiv(event)">
</div>
<div id="hidDiv" style="width: 238px; position: absolute; display: none; height: 120px;left: 228px; top: 22px; background-color: #ffcc33;">
</div>
</body>
</html>
相关文章推荐
- offsetLeft与style.left的区别 event.altKey、event.ctrlKey、event.shiftKey 属性 clientWidth和offsetWidth
- JS获取浮动(float)元素的style.left值为空的快速解决办法
- jsp页面给value属性赋值时空格问题
- style.left 与 style.top 在 IE和FireFox的兼容问题
- WEB前端animation和鼠标hover事件属性改变问题。
- 解决AngularJS使用ng-bind-html会过滤html中style属性的问题
- iOS8中UITableView的separator insets属性赋值无效的问题
- Java循环赋值和循环设置属性问题
- JS获取元素属性、样式getComputedStyle()和currentStyle方法兼容性问题
- C#中字段、属性、只读、构造函数赋值、反射赋值的问题
- Android中style资源中的<android:Theme.Dialog>属性找不到的问题
- mybatis无法给带有下划线属性赋值问题
- Android 关于重写一个居中的Dialog时,背景图片显示不全的问题。Dialog的style属性介绍
- C#中的ComboBoxEX控件的行为属性里的DropDownStyle属性的问题
- android:scrollbarStyle属性及滚动条和分割线覆盖问题
- 关于java中Serializable序列化问题中属性赋值总结
- HTML onmousedown 事件属性 关于鼠标按键的问题;
- IE firefox div 设置left的属性问题
- 鼠标左键双击图标出现属性窗口的问题
- AngularJS使用ng-bind-html会过滤html中style属性的问题