aframe register componet add onclick attribute

不想你离开。 提交于 2020-05-17 08:49:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!