Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS2DRenderer / CSS3DRenderer: allow usage of existing DOM element #22635

Merged
merged 5 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion docs/examples/en/renderers/CSS2DRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ <h2>Examples</h2>

<h2>Constructor</h2>

<h3>[name]()</h3>
<h3>[name]( [param:Object parameters] )</h3>
<p>
[page:DOMElement element] - A [link:https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement HTMLElement]
where the renderer appends its child-elements.
This corresponds to the [page:CSS2DRenderer.domElement domElement] property below.
If not passed in here, a new div element will be created.
</p>

<h2>Properties</h2>

<h3>[property:DOMElement domElement]</h3>
<p>
A [link:https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement HTMLElement] where the renderer appends its child-elements.<br />
This is automatically created by the renderer in the constructor (if not provided already).
</p>

<h2>Methods</h2>

Expand Down
16 changes: 15 additions & 1 deletion docs/examples/en/renderers/CSS3DRenderer.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,21 @@ <h2>Examples</h2>

<h2>Constructor</h2>

<h3>[name]()</h3>
<h3>[name]( [param:Object parameters] )</h3>
<p>
[page:DOMElement element] - A [link:https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement HTMLElement]
where the renderer appends its child-elements.
This corresponds to the [page:CSS3DRenderer.domElement domElement] property below.
If not passed in here, a new div element will be created.
</p>

<h2>Properties</h2>

<h3>[property:DOMElement domElement]</h3>
<p>
A [link:https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement HTMLElement] where the renderer appends its child-elements.<br />
This is automatically created by the renderer in the constructor (if not provided already).
</p>

<h2>Methods</h2>

Expand Down
9 changes: 5 additions & 4 deletions examples/jsm/renderers/CSS2DRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {

class CSS2DObject extends Object3D {

constructor( element ) {
constructor( element = document.createElement( 'div' ) ) {

super();

this.element = element || document.createElement( 'div' );
this.element = element;

this.element.style.position = 'absolute';
this.element.style.userSelect = 'none';
Expand Down Expand Up @@ -57,7 +57,7 @@ const _b = new Vector3();

class CSS2DRenderer {

constructor() {
constructor( parameters = {} ) {

const _this = this;

Expand All @@ -68,7 +68,8 @@ class CSS2DRenderer {
objects: new WeakMap()
};

const domElement = document.createElement( 'div' );
const domElement = parameters.element !== undefined ? parameters.element : document.createElement( 'div' );

domElement.style.overflow = 'hidden';

this.domElement = domElement;
Expand Down
9 changes: 5 additions & 4 deletions examples/jsm/renderers/CSS3DRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const _scale = new Vector3();

class CSS3DObject extends Object3D {

constructor( element ) {
constructor( element = document.createElement( 'div' ) ) {

super();

this.element = element || document.createElement( 'div' );
this.element = element;
this.element.style.position = 'absolute';
this.element.style.pointerEvents = 'auto';
this.element.style.userSelect = 'none';
Expand Down Expand Up @@ -87,7 +87,7 @@ const _matrix2 = new Matrix4();

class CSS3DRenderer {

constructor() {
constructor( parameters = {} ) {

const _this = this;

Expand All @@ -99,7 +99,8 @@ class CSS3DRenderer {
objects: new WeakMap()
};

const domElement = document.createElement( 'div' );
const domElement = parameters.element !== undefined ? parameters.element : document.createElement( 'div' );

domElement.style.overflow = 'hidden';

this.domElement = domElement;
Expand Down