blob: 009b338b12af5d10373c2e246b035e9094bd41a7 (
plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
---
title: MouseEvent.clientX
slug: Web/API/MouseEvent/clientX
tags:
- API
- DOM
- DOM Events
translation_of: Web/API/MouseEvent/clientX
---
<p>{{APIRef("DOM Events")}}</p>
<p><strong><code>MouseEvent.clientX</code></strong> 是只读属性, 它提供事件发生时的应用客户端区域的水平坐标 (与页面坐标不同)。例如,不论页面是否有水平滚动,当你点击客户端区域的左上角时,鼠标事件的 <code>clientX</code> 值都将为 0 。最初这个属性被定义为长整型(long integer),如今 <strong>CSSOM </strong>视图模块将其重新定义为双精度浮点数(double float)。你可以查阅浏览器兼容性部分的文档来进一步了解有关信息。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox"><code>
var <em>x</em> = <em>instanceOfMouseEvent</em>.clientX
</code></pre>
<h3 id="返回值"><code>返回值</code></h3>
<p>被 CSSOM View Module 重新定义为一个 <code>double</code> 类型的浮点值. 原来这个属性是被定义为一个 <code>long</code> 整数. 可以在 "浏览器兼容性" 那里查看详细内容.</p>
<h2 id="Example" name="Example">示例</h2>
<pre class="brush: html"><!DOCTYPE html>
<html>
<head>
<title>clientX/clientY example</title>
<script>
function showCoords(evt){
alert(
"clientX value: " + evt.clientX + "\n" +
"clientY value: " + evt.clientY + "\n"
);
}
</script>
</head>
<body onmousedown="showCoords(event)">
<p>To display the mouse coordinates click anywhere on the page.</p>
</body>
</html>
</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('CSSOM View','#dom-mouseevent-clientx', 'clientX')}}</td>
<td>{{Spec2('CSSOM View')}}</td>
<td>Redefines {{domxref("MouseEvent")}} from <code>long</code> to <code>double</code>.</td>
</tr>
<tr>
<td>{{SpecName('DOM3 Events','#widl-MouseEvent-clientX','MouseEvent.clientX')}}</td>
<td>{{Spec2('DOM3 Events')}}</td>
<td>No change from {{SpecName('DOM2 Events')}}.</td>
</tr>
<tr>
<td>{{SpecName('DOM2 Events','#Events-MouseEvent','MouseEvent.clientX')}}</td>
<td>{{Spec2('DOM2 Events')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>
<p>{{Compat("api.MouseEvent.clientX")}}</p>
<h2 id="See_also" name="See_also">相关</h2>
<ul>
<li><code><code>{{ domxref("MouseEvent") }}</code></code></li>
<li><code><code>{{domxref("event.clientY","clientY")}}</code></code></li>
<li><code><code>{{domxref("event.screenX","screenX")}} / {{domxref("event.screenY","screenY")}}</code></code></li>
</ul>
|