aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/document
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/document')
-rw-r--r--files/zh-cn/web/api/document/elementfrompoint/index.html86
-rw-r--r--files/zh-cn/web/api/document/elementsfrompoint/index.html51
2 files changed, 137 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/document/elementfrompoint/index.html b/files/zh-cn/web/api/document/elementfrompoint/index.html
new file mode 100644
index 0000000000..5a0cdd7ffc
--- /dev/null
+++ b/files/zh-cn/web/api/document/elementfrompoint/index.html
@@ -0,0 +1,86 @@
+---
+title: DocumentOrShadowRoot.elementFromPoint()
+slug: Web/API/Document/elementFromPoint
+translation_of: Web/API/DocumentOrShadowRoot/elementFromPoint
+original_slug: Web/API/DocumentOrShadowRoot/elementFromPoint
+---
+<p>{{APIRef("Shadow DOM")}}{{SeeCompatTable}}</p>
+
+<p><span class="seoSummary">{{domxref("DocumentOrShadowRoot")}} 接口的 <strong><code>elementFromPoint()</code></strong> 方法返回给定坐标点下最上层的 {{domxref('element')}} 元素。 </span></p>
+
+<p>If the element at the specified point belongs to another document (for example, an iframe's subdocument), the subdocument's parent element is returned (the iframe itself). If the element at the given point is anonymous or XBL generated content, such as a textbox's scroll bars, then the first non-anonymous ancestor element (for example, the textbox) is returned.</p>
+
+<p>如果指定的坐标点在文档的可视范围外,或者两个坐标都是负数,那么结果返回 <code>null</code>。</p>
+
+<p>If you need to find the specific position inside the element, use {{domxref("Document.caretPositionFromPoint()")}}.</p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox notranslate">var element = document.elementFromPoint(x, y);</pre>
+
+<h3 id="Parameters">Parameters</h3>
+
+<dl>
+ <dt>x</dt>
+ <dd>坐标点的横坐标。</dd>
+ <dt>y</dt>
+ <dd>坐标点的纵坐标。</dd>
+</dl>
+
+<h3 id="Returns">Returns</h3>
+
+<p>在给定的坐标点处的顶端 {{domxref("Element")}}(译者注:如果元素层叠的话,返回最上层的元素)。</p>
+
+<h2 id="Example" name="Example">Example</h2>
+
+<pre class="brush:html notranslate" id="ExampleCode">&lt;!DOCTYPE html&gt;
+&lt;html lang="en"&gt;
+&lt;head&gt;
+&lt;title&gt;elementFromPoint example&lt;/title&gt;
+
+&lt;script&gt;
+function changeColor(newColor) {
+ elem = document.elementFromPoint(2, 2);
+ elem.style.color = newColor;
+}
+&lt;/script&gt;
+&lt;/head&gt;
+
+&lt;body&gt;
+&lt;p id="para1"&gt;Some text here&lt;/p&gt;
+&lt;button onclick="changeColor('blue');"&gt;blue&lt;/button&gt;
+&lt;button onclick="changeColor('red');"&gt;red&lt;/button&gt;
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+<h3 id="Demo">Demo</h3>
+
+<p>{{ EmbedLiveSample('Example', '', '', '', 'Web/API/Document/elementFromPoint') }}</p>
+
+
+
+<h2 id="Specifications">Specifications</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('Shadow DOM','#extensions-to-the-documentorshadowroot-mixin','DocumentOrShadowRoot')}}</td>
+ <td>{{Spec2('Shadow DOM')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_Compatibility">Browser Compatibility</h2>
+
+<div>
+
+
+<p>{{Compat("api.DocumentOrShadowRoot.elementFromPoint")}}</p>
+</div>
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..bea911988b
--- /dev/null
+++ b/files/zh-cn/web/api/document/elementsfrompoint/index.html
@@ -0,0 +1,51 @@
+---
+title: DocumentOrShadowRoot.elementsFromPoint()
+slug: Web/API/Document/elementsFromPoint
+translation_of: Web/API/DocumentOrShadowRoot/elementsFromPoint
+original_slug: Web/API/DocumentOrShadowRoot/elementsFromPoint
+---
+<p>{{APIRef("Shadow DOM")}}{{SeeCompatTable}}</p>
+
+<p><span class="seoSummary"><strong><code>elementsFromPoint()</code></strong> 是 {{domxref("DocumentOrShadowRoot")}} 下的一个函数,该函数返还在特定坐标点下的HTML元素数组。</span></p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">var elements = document.elementsFromPoint(x, y);</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt>x</dt>
+ <dd>坐标点的水平坐标值</dd>
+ <dt>y</dt>
+ <dd>坐标点的垂向坐标值</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p>一个包含 {{domxref('element')}} 对象的数组.</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('Shadow DOM','','elementsFromPoint()')}}</td>
+ <td>{{Spec2('Shadow DOM')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div>
+
+
+<p>{{Compat("api.DocumentOrShadowRoot.elementsFromPoint")}}</p>
+</div>