How to get click event with javascript from an A-frame element

gabor aron picture gabor aron · Nov 14, 2016 · Viewed 9.8k times · Source

UPDATE: You can use onclick= function();in the HTML.

For example: <a-box onclick="myFunction()"></a-box>

I want to get click event of cursor with javascript from an A-frame element, like a box for example, how can I do it?

Answer

ngokevin picture ngokevin · Nov 14, 2016

If you are using the cursor component:

box.addEventListener('click', function (evt) { // ... });

If you want to use the mouse cursor, try https://www.npmjs.com/package/aframe-mouse-cursor-component