Skip to main content

Registering Event Handlers

Basics

Event handlers can be added in two ways.

  1. Add event handlers before initialization with the option on
const view3D = new View3D("#el", {
on: {
ready: evt => {
// DO_SOMETHING
}
}
});
  1. Add event handlers at anytime with on, once
const view3D = new View3D("#el");

view3D.on("load", evt => {
// This will be called everytime when the 3D model is loaded
});

view3D.once("load", evt => {
// This will be called once for the first loaded model.
});

You can detach these handlers at anytime by calling off.

const view3D = new View3D("#el");

const handler = () => {
console.log("render");
};

// Attach handler
view3D.on("render", handler);

// Detach handler
view3D.off("render", handler);

Frameworks

import View3D, { EVENTS, RenderEvent } from "@egjs/view3d";

// For Typescript users: You can specify event types like this
const onRender = (evt: RenderEvent) => {
// DO_SOMETHING
};

view3D.on(EVENTS.RENDER, onRender);