鼠标移动事件

来源:互联网 发布:淘宝客如何获取内部券 编辑:程序博客网 时间:2024/05/15 03:59
一 介绍
鼠标移动事件(onmousemove)是鼠标在页面上进行移动时触发事件处理程序,可以在该事件中用document对象实时读取鼠标在页面中的位置。
 
二 应用
在状态栏中显示鼠标在页面中的当前位置
本示例是鼠标在页面中移动时,在页面的状态栏中显示当前鼠标在页面上的位置,也就是(x, y)值。结果如图7所示。
 
三 代码
<script language="javascript"><!--var x=0,y=0;function MousePlace(){ x=window.event.x; y=window.event.y; window.status="X: "+x+" "+"Y: "+y+" ";}document.onmousemove=MousePlace;//--></script>
 
四 运行结果