简体   繁体   中英

Aframe: How to set an entity class with js?

i'm adding aframe entities programmatically.

I didn't find how to set their class so that they get raycaster events.

i tried this without succes:

this.el.setAttribute('class', 'link');

or:

this.el.className = "link";

From the docs (I'm linking MDN, for this is not aframe exclusive):

Add a class using

this.el.classList.add("myClass");

Remove it using

this.el.classList.remove("myClass");


You can check out this fiddle where i add/remove classes to set which objects are clickable. Here with a mouse-cursor instead of the classic one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM