鼠标事件以及clientX、offsetX、screenX、pageX、x的区别

鼠标事件
鼠标事件有下面这几种:blog

1. onclick
鼠标点击事件seo

box.onclick = function(e){
  console.log(e)
}
2. onmousedown
鼠标按下事件事件

box.onmousedown = function(e){
  console.log(e)
}

3. onmouseup
鼠标松开事件io

box.onmouseup = function(e){
  console.log(e)
}console


4. onmousemove
鼠标移动事件function

box.onmousemove = function(e){
  console.log(e)
}

5. onmouseover
鼠标通过事件cli

box.onmouseover = function(e){
  console.log(e)
}

6. onmouseout
鼠标划出事件sed

box.onmouseout = function(e){
  console.log(e)
}

根据以上打印的e的信息,大体为:im

 

由鼠标事件(MouseEvent)能够发现:
       其中包含了许多的坐标,且每一个坐标的含义都不同。下面咱们来挨个介绍经常使用的坐标,以及它们的含义。img

1、clientX、clientY
点击位置距离当前body可视区域的x,y坐标

2、pageX、pageY
对于整个页面来讲,包括了被卷去的body部分的长度

3、screenX、screenY
点击位置距离当前电脑屏幕的x,y坐标

4、offsetX、offsetY
相对于带有定位的父盒子的x,y坐标

5、x、y
和screenX、screenY同样

如图所示:


相关文章
相关标签/搜索