Skip to content

Commit d454e68

Browse files
authored
feat: add VFXProps.overlay (#78)
1 parent 1d0bd17 commit d454e68

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/vfx-js/src/types.ts

+14
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ export type VFXProps = {
8585
*/
8686
uniforms?: VFXUniforms;
8787

88+
/**
89+
* The opacity for the original HTML element.
90+
*
91+
* By default, VFX-JS hides the original element by setting its opacity to 0.
92+
* However, in some cases you might want not to hide the original element.
93+
* `overlay` allows you to specify the opacity to be set explicitly.
94+
*
95+
* If you pass `true`, VFX-JS will preserve the original element's opacity.
96+
*
97+
* You can also specify the opacity by passing a number.
98+
* For example, `overlay: 0.5` will set the opacity of the orignal element to 0.5.
99+
*/
100+
overlay?: true | number;
101+
88102
/**
89103
* Allow shader outputs to oveflow the original element area.
90104
* If true, REACT-VFX will render the shader in fullscreen.

packages/vfx-js/src/vfx-player.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,14 @@ export class VFXPlayer {
217217
texture.needsUpdate = true;
218218

219219
// Hide original element
220-
const opacity = type === "video" ? "0.0001" : "0"; // don't hide video element completely to prevent jank frames
221-
element.style.setProperty("opacity", opacity);
220+
if (opts.overlay === true) {
221+
/* Overlay mode. Do not hide the element */
222+
} else if (typeof opts.overlay === "number") {
223+
element.style.setProperty("opacity", opts.overlay.toString());
224+
} else {
225+
const opacity = type === "video" ? "0.0001" : "0"; // don't hide video element completely to prevent jank frames
226+
element.style.setProperty("opacity", opacity.toString());
227+
}
222228

223229
const uniforms: { [name: string]: THREE.IUniform } = {
224230
src: { value: texture },

0 commit comments

Comments
 (0)