问题
I want to create dynamic componet using aframe But I cannot add onclick on my component
this my code
AFRAME.registerComponent('cylinders', {
init: function(){
let el = this.el;
let sceneEl = document.getElementById('scene1');
let cyl = document.createElement('a-cylinder');
cyl.setAttribute('position', '0 0 0');
cyl.setAttribute('rotation', '0 0 0');
cyl.setAttribute('scale', '0 0 0');
cyl.setAttribute('radius', 1);
cyl.setAttribute('height', 0.1);
cyl.setAttribute('color', '#39BB82');
cyl.setAttribute('checkpoint', '');
cyl.setAttribute('class', 'clickable');
cyl.setAttribute('onclick', 'myFunction()');
sceneEl.appendChild(cyl);
}
}
});
my code working fine, but I cannot set onlick. If i write like this bottom I can use onclick.
<a-cylinder
class="clickable"
checkpoint=""
radius="1"
height="0.1"
position="0 0 0"
rotation="0 0 0"
scale="0 0 0"
onclick="myFunction()"
color="#39BB82">
</a-cylinder>
can some one help me? I just need registerComponent working with my onclick
来源:https://stackoverflow.com/questions/61807274/aframe-register-componet-add-onclick-attribute