利用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. C语言 static静态变量

    静态变量类型说明符是static. 静态变量属于静态存储方式,其存储空间为内存中的静态数据区(在 静态存储区内分配存储单元),该区域中的数据在整个程序的运行期间一直占用这些存储空间(在程序整个运行期间 ...

  2. Session和几种状态保持方案理解

    一.术语session 在我的经验里,session这个词被滥用的程度大概仅次于transaction,更加有趣的是transaction与session在某些语境下的含义是相同的. session, ...

  3. 如何对抗、预防 SQL注入 攻击

    一.SQL注入简介 SQL注入是比较常见的网络攻击方式之一,它不是利用操作系统的BUG来实现攻击,而是针对程序员编程时的疏忽,通过SQL语句,实现无帐号登录,甚至篡改数据库. 二.SQL注入攻击的总体 ...

  4. par函数fg参数-控制前景色

    fg参数用来控制前景色,其实指的就是x轴和y轴的轴线和刻度线的颜色 在R语言中,会根据fg, col 任何一个参数的值,自动的将两个参数的值设置为相同的值,举个例子: par(fg = "r ...

  5. 世界上最痛苦的事就是去改别人的bug!!!!

    世界上最痛苦的事就是去改别人的bug!!!!

  6. 【Java NIO的深入研究2】RandomAccessFile的使用

    RandomAccessFile RandomAccessFile是用来访问那些保存数据记录的文件的,你就可以用seek( )方法来访问记录,并进行读写了.这些记录的大小不必相同:但是其大小和位置必须 ...

  7. u3d change terrain textrue&height

    using UnityEngine; using System.Collections; public class terrainTest : MonoBehaviour { ; private Te ...

  8. 演示-JQuery关系选择器

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. Linux性能研究(总)

    http://www.vpsee.com/2009/11/linux-system-performance-monitoring-introduction/ http://www.jb51.net/L ...

  10. angular ajax的使用及controller与service分层

    一个简单的例子,控制层:.controller('publishController',['$scope','publishService', function($scope,publishServi ...