利用JavaScript获取鼠标经过位置的X、Y坐标方法。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>XYPosition</title>

<script language="javascript">
function mousePosition(ev){
   if(ev.pageX || ev.pageY){
    return {x:ev.pageX, y:ev.pageY};
   }
  return {
    x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
    y:ev.clientY + document.body.scrollTop - document.body.clientTop
  };
}

function mouseMove(ev){
  ev = ev || window.event;
  var mousePos = mousePosition(ev);
  document.getElementById('xzb').value = mousePos.x;
  document.getElementById('yzb').value = mousePos.y;
}

document.onmousemove = mouseMove;

/*
function Show(el){
//alert(el.offsetLeft);
//alert(el.offsetLeft);
var x = parseInt(document.getElementById('xzb').value)-el.offsetLeft;
var y = parseInt(document.getElementById('yzb').value)-el.offsetTop;
if (x>660 && x <760){
if(y>140 && y <360){
//alert(x+","+y);
window.location.href = "index.htm";
}
}
x = "X:"+x;
y = "Y:"+y;
//alert(x+","+y);
}
*/
</script>

</head>
<body>
X:<input id="xzb" type="text" /> Y:<input id="yzb" type="text" /></br>
<img id="imgPic" src="img/css_globe_diffuse2.jpg" onclick="Show(this)" />

</body>
</html>

获取鼠标经过位置的X、Y坐标的更多相关文章

  1. js获取鼠标的位置

    <!doctype html><html><head><meta charset="utf-8"><title>获取鼠标 ...

  2. WPF 获取鼠标屏幕位置、窗口位置、控件位置

    原文:WPF 获取鼠标屏幕位置.窗口位置.控件位置 public struct POINT { public int X; public int Y; public POINT(int x, int ...

  3. document.compatMode属性和获取鼠标的位置

    document.compatMode属性 document.compatMode用来判断当前浏览器采用的渲染方式. 官方解释: BackCompat:标准兼容模式关闭.CSS1Compat:标准兼容 ...

  4. HTML页面上获取鼠标的位置(备忘)

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  5. WPF获取鼠标当前位置

    /// <summary> /// 设置鼠标的坐标 /// </summary> /// <param name="x">横坐标</par ...

  6. Range对象理解,浏览器兼容性,获取鼠标光标位置

    一.关于浏览器的兼容性 目前主要有3种关于range的类似的对象,分别是W3C range 对象,Mozzlia selection ,ie TextRange 关于这三种的区别,请查看文档 http ...

  7. 2015/11/4用Python写游戏,pygame入门(4):获取鼠标的位置及运动

    按昨天的说法,今天将开始做一个简单的游戏了. 目标是拷贝微信的飞机大战,当然拷贝完以后大家就具备自己添加不同内容的能力了. 首先是要拿到一些图片素材,熟悉使用图像处理软件和绘画的人可以自己制作,并没有 ...

  8. (转)linux如何获取鼠标相对位置信息

    #include <stdio.h> #include <stdlib.h> #include <linux/input.h> #include <fcntl ...

  9. Cesium 获取鼠标当前位置的模型高度,地形高度,OSGB高度,及其经纬度。

    var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene._imageryLayerCollection);var ray,posit ...

随机推荐

  1. 关于Cocos2d-x中图集中图片的调用

    1.首先在Resources文件夹下要有打包好的图集文件和相同名称的plist文件. shoot.png shoot.plist shoot_background.png shoot_backgrou ...

  2. 关于Cocos2d-x头文件的引用

    cocos2d-x 3.10的G:\cocoshome\Cocos2d-x\cocos2d-x-3.10\extensions\GUI\CCControlExtension\CCScale9Sprit ...

  3. ti的硬件时钟和系统时钟同步

    1.hwclock -w软到硬 hwclock -s 硬到软 2. 通过ntp网络时钟控制同步 3.etc下的localtime文件和GMT-8

  4. CentOS简单命令学习:date cal bc

    简单的shell指令: 1.日期的格式化显示: 2.日历的显示: 3.bc计算器: 使用Tab指令自动补全:

  5. openal 基础知识2

    三枚举扩展包(enumeration extension,“ALC_ENUMERATION_EXT”) 开发者可以通过这个extension得到一个字符串列表,区分不同的渲染/捕捉设备.OpenALr ...

  6. MVC Razor与javascript混编(js中嵌入razor)

    其中的关键是输出js上的纯文本内容,让浏览器解析为其中的js代码 <script>    BUI.use('common/main',function(){        var conf ...

  7. jQuery继承extend用法详解

    /直接基于jQuery的扩展,判断是否为空 $.isBlank = function(obj){   return(typeof(obj)=='undefined'||obj==''||obj==nu ...

  8. mysql connection不断增加

    程序运行以后,刷新页面,在mysql的status里面检测到Threads_connected的值不断上升. 对程序断点调试,发现,是由于下面的代码导致. class ConnectionMySQL( ...

  9. ChemOffice Professional 16.0新增了哪些功能

    ChemOffice Professional 16.0是为终极化学和生物组件设计,可满足化学家和生物学家的需求.ChemOffice Professional帮助科学家有效地检索数据库,包括SciF ...

  10. TCP/IP协议族-----24、网络管理(SNMP)