1. offset:其定位原点是当前元素左上角
2. client:其定位原点是当前窗口左上角
3. page:其定位原点是当前页面左上角
下面来验证一下。
先上代码:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type="text/javascript" src="http://www.likecs.com/jquery-1.12.3.js"></script> <style> * { margin: 0px; padding: 0px; } #div1 { width: 200px; height: 200px; position: absolute; top: 400px; left: 100px; background-color: rebeccapurple; } </style> <script> $(function(){ $("#div1").click(function(event){ console.log("offsetX值为:"+event.offsetX," offsetY值为:"+event.offsetY); console.log("clientX值为:"+event.clientX," clientY值为:"+event.clientY); console.log("pageX值为:"+event.pageX," pageY值为:"+event.pageY); console.log("---------------------------------------") }) }) </script> </head> <body> <div></div> </body> </html>