鼠标事件
鼠标事件有下面这几种:markdown
1. onclick
鼠标点击事件spa
box.onclick = function(e){ console.log(e) }
- 1
- 2
- 3
2. onmousedown
鼠标按下事件code
box.onmousedown = function(e){ console.log(e) }
- 1
- 2
- 3
3. onmouseup
鼠标松开事件blog
box.onmouseup = function(e){ console.log(e) }
- 1
- 2
- 3
4. onmousemove
鼠标移动事件seo
box.onmousemove = function(e){ console.log(e) }
- 1
- 2
- 3
5. onmouseover
鼠标通过事件事件
box.onmouseover = function(e){ console.log(e) }
- 1
- 2
- 3
6. onmouseout
鼠标划出事件图片
box.onmouseout = function(e){ console.log(e) }
- 1
- 2
- 3
根据以上打印的e的信息,大体为:it
由鼠标事件(MouseEvent)能够发现:
其中包含了许多的坐标,且每一个坐标的含义都不同。下面咱们来挨个介绍经常使用的坐标,以及它们的含义。io
1、clientX、clientY
点击位置距离当前body可视区域的x,y坐标console
2、pageX、pageY
对于整个页面来讲,包括了被卷去的body部分的长度
3、screenX、screenY
点击位置距离当前电脑屏幕的x,y坐标
4、offsetX、offsetY
相对于带有定位的父盒子的x,y坐标
5、x、y
和screenX、screenY同样
如图所示: