鼠标定位问题?

jianglin28290 2008-03-28 11:08:33
function Show_Pop_Menu() {
var x=0;
var y=0;
var evn = new getEvent();
if (navigator.appName=='Microsoft Internet Explorer') {
x=evn.x;
y=evn.y;
} else {
x=evn.pageX;
y=evn.pageY;
}
document.getElementById("Pop_Menu").style.visibility="visible";
document.getElementById("Pop_Menu").style.left=x;
document.getElementById("Pop_Menu").style.top=y;
}


function getEvent()
{
if(document.all) return window.event;
func=getEvent.caller;
while(func!=null) {
var arg0=func.arguments[0];
if(arg0) {
if((arg0.constructor==Event || arg0.constructor ==MouseEvent) ||(typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) {
return arg0;
}
}
func=func.caller;
}
return null;
}
为什么鼠标定位紊乱?
...全文
136 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
No_Data_Found 2008-03-28
  • 打赏
  • 举报
回复

document.getElementById("Pop_Menu").style.left=x + "px";
document.getElementById("Pop_Menu").style.top=y + "px";
jnwentao 2008-03-28
  • 打赏
  • 举报
回复
这样就可以了
<html><head>
<script>
function mousexy(event){
id.value= "X:" + (event.clientX + document.body.scrollLeft) +"px;Y:"+ (event.clientY+document.body.scrollTop)+"px;";
}
</script>
</head><body onMouseMove="mousexy(event);"><input id="id" type="text"></body></html>
加上event就可以兼容firefox
scrollLeft与scrollTop是卷去的页面部份,应加上它,不然就会出现mouse位置混乱的情况
ymle1228 2008-03-28
  • 打赏
  • 举报
回复
学习
loveyunwt 2008-03-28
  • 打赏
  • 举报
回复


<script language="javascript">


function show(str){
document.getElementById("xx").style.left = window.event.clientX - 100 ;//鼠标位置
document.getElementById("xx").style.top = window.event.clientY + 15 ;
if (document.getElementById("xx").style.display =="none")
{
document.getElementById("xx").innerHTML=str;
document.getElementById("xx").style.display ="block";

}
else if(document.getElementById("xx").style.display == "block")
{
document.getElementById("xx").innerHTML=str;
document.getElementById("xx").style.display ="none";
}
}
</script>

<input value="1" onMouseOver="show(this.value);" onMouseOut="show(this.value);"><br/><br/><br/>
<input value="2" onMouseOver="show(this.value);" onMouseOut="show(this.value);"><br/><br/><br/>
<input value="3" onMouseOver="show(this.value);" onMouseOut="show(this.value);"><br/><br/><br/>
<input value="4" onMouseOver="show(this.value);" onMouseOut="show(this.value);"><br/><br/><br/>
<input value="5" onMouseOver="show(this.value);" onMouseOut="show(this.value);"><br/><br/><br/>

<div id="xx" style="position:absolute; display:none;"></div>

jianglin28290 2008-03-28
  • 打赏
  • 举报
回复
我试过了,仍然不行啊

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧