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