复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53<html> <head> <title>位置</title> <style> .test { background: url("image/omeoclickimg.jpg"); } </style> <script language="javascript" type="text/javascript"> function c() { var objTop = getOffsetTop(document.getElementById("d"));//对象x位置 var objLeft = getOffsetLeft(document.getElementById("d"));//对象y位置 var mouseX = event.clientX + document.body.scrollLeft;//鼠标x位置 var mouseY = event.clientY + document.body.scrollTop;//鼠标y位置 //计算点击的相对位置 var objX = mouseX - objLeft; var objY = mouseY - objTop; clickObjPosition = objX + "," + objY; alert(clickObjPosition); } function getOffsetTop(obj) { var tmp = obj.offsetTop; var val = obj.offsetParent; while (val != null) { tmp += val.offsetTop; val = val.offsetParent; } return tmp; } function getOffsetLeft(obj) { var tmp = obj.offsetLeft; var val = obj.offsetParent; while (val != null) { tmp += val.offsetLeft; val = val.offsetParent; } return tmp; } </script> </head> <body style="margin:0px;"> <div style="padding:90px;border:1px solid #ccc;font-size:36px;width:800px;height:800px;"></div> <div id="area"></div> <div style="width:1400px;height:300px;border:1px solid red;padding-left:1200px;"> <div id="d" class="test" style="width:230px;height:230px;border:1px solid green;padding:10px;cursor:hand;" onclick="c()"></div> </div> </body> </html>
最后
以上就是健康火车最近收集整理的关于Selenium_获取相对坐标的全部内容,更多相关Selenium_获取相对坐标内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复