aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/document/elementsfrompoint/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/document/elementsfrompoint/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/document/elementsfrompoint/index.html')
-rw-r--r--files/zh-cn/web/api/document/elementsfrompoint/index.html128
1 files changed, 128 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/document/elementsfrompoint/index.html b/files/zh-cn/web/api/document/elementsfrompoint/index.html
new file mode 100644
index 0000000000..855f793460
--- /dev/null
+++ b/files/zh-cn/web/api/document/elementsfrompoint/index.html
@@ -0,0 +1,128 @@
+---
+title: Document.elementsFromPoint()
+slug: Web/API/Document/elementsFromPoint
+translation_of: Web/API/DocumentOrShadowRoot/elementsFromPoint
+---
+<div>{{APIRef("DOM")}}{{SeeCompatTable}}</div>
+
+<p><code><strong>elementsFromPoint()</strong></code> 方法可以获取到当前视口内指定坐标处,由里到外排列的所有元素。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="brush: js">var<em> elements</em> = <em>document</em>.elementsFromPoint(<em>x</em>, <em>y</em>);</pre>
+
+<h3 id="返回值">返回值</h3>
+
+<p>一个包含多个元素的数组</p>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt>x</dt>
+ <dd>当前视口内某一点的横坐标</dd>
+ <dt>y</dt>
+ <dd>当前视口内某一点的纵坐标</dd>
+</dl>
+
+<h2 id="Example" name="Example">示例</h2>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;div&gt;
+ &lt;p&gt;Some text&lt;/p&gt;
+&lt;/div&gt;
+&lt;p&gt;Elements at point 30, 20:&lt;/p&gt;
+&lt;div id="output"&gt;&lt;/div&gt;
+</pre>
+
+<h3 id="JavaScript">JavaScript</h3>
+
+<pre class="brush: js;highlight[1]">var output = document.getElementById("output");
+if (document.elementsFromPoint) {
+ var elements = document.elementsFromPoint(30, 20);
+ for(var i = 0; i &lt; elements.length; i++) {
+ output.textContent += elements[i].localName;
+ if (i &lt; elements.length - 1) {
+ output.textContent += " &lt; ";
+ }
+ }
+} else {
+ output.innerHTML = "&lt;span style=\"color: red;\"&gt;" +
+ "您的浏览器不支持 &lt;code&gt;document.elementsFromPoint()&lt;/code&gt;" +
+ "&lt;/span&gt;";
+}</pre>
+
+<p>{{EmbedLiveSample('Example', '420', '120')}}</p>
+
+<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-document-elementsfrompoint', 'elementsFromPoint')}}</td>
+ <td>{{Spec2('CSSOM View')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td> {{CompatChrome(43.0)}}</td>
+ <td>{{CompatGeckoDesktop("46.0")}}<sup>[1]</sup></td>
+ <td>10.0 {{property_prefix("ms")}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatSafari(11)}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Android Webview</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ <th>Chrome for Android</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatNo}}</td>
+ <td>{{CompatChrome(43.0)}}</td>
+ <td>{{CompatGeckoMobile("46.0")}}<sup>[1]</sup></td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatSafari(11)}}</td>
+ <td>{{CompatChrome(43.0)}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<p> </p>