利用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语言 常用的宏定义

    __FILE__ :宏在预编译时会替换成当前的源文件名 __LINE__:宏在预编译时会替换成当前的行号 __FUNCTION__:宏在预编译时会替换成当前的函数名称 //宏__VA_ARGS__的用 ...

  2. Struts tags--Data tags

      struts tags详解之<s:bean> Description     Bean标签,当然需要一个JavaBean.它的属性值的操作是经由Bean标签中的参数属性来进行赋值.当然 ...

  3. 多媒体开发之rtcp详解---rtcp数据包

    http://www.360doc.com/content/13/0606/10/1317564_290865866.shtml http://blog.csdn.net/hrbeuwhw/artic ...

  4. erlang二进制的难理解的地方,有点神奇

    40> <<A:16>> = <<1,2>>.<<1,2>>41> <<B:16/bits>> ...

  5. php下保存远程图片到本地的函数

    <?php header("content-type:text/html;charset=utf-8"); function GrabImage($url,$filename ...

  6. jquery-包裹元素

    1.wrap方法 在每个匹配的元素外层包上一个html元素 参数类型说明: 1)html字符串 $('p').wrap('<div></div>'); 传入的html标签也可以 ...

  7. Linux配置防火墙,开启80port、3306port 可能会遇到的小问题

     vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(同意80端口通 ...

  8. kafka学习之-配置详解

    # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreement ...

  9. C# 多线程操作队列

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  10. MySQL性能优化(四)-- MySQL explain详解

    前言 MySQL中的explain命令显示了mysql如何使用索引来处理select语句以及连接表.explain显示的信息可以帮助选择更好的索引和写出更优化的查询语句. 一.格式 explain + ...