blob: 0e3dd27717a053cc1410cffa78fd061f81b8f248 (
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
|
---
title: DocumentOrShadowRoot
slug: Web/API/DocumentOrShadowRoot
tags:
- API
- DocumentOrShadowRoot
- Interface
- NeedsTranslation
- Reference
- TopicStub
- shadow dom
translation_of: Web/API/DocumentOrShadowRoot
---
<div>{{APIRef("Web Components")}}</div>
<p><span class="seoSummary"><a href="/zh-CN/docs/Web/Web_Components/Using_shadow_DOM">Shadow DOM API</a> 的 <strong><code>DocumentOrShadowRoot</code></strong> 接口提供了 documents 与 shadow roots 之间共享的 API。The following features are included in both {{DOMxRef("Document")}} and {{DOMxRef("ShadowRoot")}}.</span></p>
<h2 id="属性">属性</h2>
<dl>
<dt>{{DOMxRef("DocumentOrShadowRoot.activeElement")}}{{ReadOnlyInline}}</dt>
<dd>Returns the {{DOMxRef('Element')}} within the shadow tree that has focus.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.fullscreenElement")}}{{ReadOnlyInline}}</dt>
<dd>Returns the {{DOMxRef('Element')}} that's currently in full screen mode for this document.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.pointerLockElement")}} {{Experimental_Inline}}{{ReadOnlyInline}}</dt>
<dd>Returns the element set as the target for mouse events while the pointer is locked. It returns <code>null</code> if lock is pending, the pointer is unlocked, or if the target is in another document.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.styleSheets")}}{{ReadOnlyInline}}</dt>
<dd>Returns a {{DOMxRef('StyleSheetList')}} of {{DOMxRef('CSSStyleSheet')}} objects for stylesheets explicitly linked into, or embedded in a document.</dd>
</dl>
<h2 id="方法">方法</h2>
<dl>
<dt>{{DOMxRef("DocumentOrShadowRoot.caretPositionFromPoint()")}}</dt>
<dd>Returns a {{DOMxRef('CaretPosition')}} object containing the DOM node containing the caret, and caret's character offset within that node.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.elementFromPoint()")}}</dt>
<dd>Returns the topmost element at the specified coordinates.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.elementsFromPoint()")}}</dt>
<dd>Returns an array of all elements at the specified coordinates.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.getSelection()")}}</dt>
<dd>Returns a {{DOMxRef('Selection')}} object representing the range of text selected by the user, or the current position of the caret.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.nodeFromPoint()")}} {{non-standard_inline}}</dt>
<dd>Returns the topmost node at the specified coordinates.</dd>
<dt>{{DOMxRef("DocumentOrShadowRoot.nodesFromPoint()")}} {{non-standard_inline}}</dt>
<dd>Returns an array of all nodes at the specified coordinates.</dd>
</dl>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('Shadow DOM','#extensions-to-the-documentorshadowroot-mixin','DocumentOrShadowRoot')}}</td>
<td>{{Spec2('Shadow DOM')}}</td>
<td>Implementation in Shadow DOM.</td>
</tr>
<tr>
<td>{{SpecName('DOM WHATWG','#mixin-documentorshadowroot','DocumentOrShadowRoot')}}</td>
<td>{{Spec2('DOM WHATWG')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.DocumentOrShadowRoot")}}</p>
<p>[1] This interface's features are still implemented on the {{DOMxRef("Document")}} object.</p>
|