教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 js获取鼠标坐标 js获取鼠标像素点

js获取鼠标坐标 js获取鼠标像素点

发布时间:2015-07-04   编辑:jiaochengji.com
本文介绍了js获取鼠标坐标,以及js获取鼠标像素点的实例代码,有需要的朋友参考下。

使用js获取鼠标坐标,获取鼠标像素点,运行本页面后,随意移动鼠标的位置,可适时显现鼠标的坐标点,不占用系统资源。

代码:
 

复制代码 代码示例:
<!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>
<title>javascript获取鼠标坐标--www.jiaochengji.com</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<style type="text/css">
.tip {
width:200px;
border:2px solid #ddd;
padding:8px;
background:#f1f1f1;
color:#666;
}
</style>
<script type="text/javascript">
function mousepos(e){
var x,y;
var e = e||window.event;
return {
x:e.clientx+document.body.scrollleft+document.documentelement.scrollleft,
y:e.clienty+document.body.scrolltop+document.documentelement.scrolltop
};
};
function test(e){
document.getelementbyid("mjs").innerhtml = mousepos(e).x+','+mousepos(e).y;
};
</script>
</head>
<body>
<div id="mjs" class="tip">教程集 www.jiaochengji.com 编辑整理</div>
<div id="test" style="width:1000px;height:1000px;background:#ccc;" onmousemove="test(event)"></div>
</body>
</html>

您可能感兴趣的文章:
js获取鼠标坐标 js获取鼠标像素点
Js代码获取鼠标点击的坐标
C# 获取鼠标相对当前窗口坐标的方法
js与jquery中获取当前鼠标的x、y坐标位置的代码
jQuery 拖动层(在可视区域范围内)
js 获取鼠标实时坐标的代码
如何利用canvas实现按住鼠标移动绘制出轨迹
jQuery 点击图片跳转上一张或下一张功能的实现代码
js中event鼠标事件的例子
js简单拖动层效果

关键词: js鼠标事件   
[关闭]
~ ~