admin管理员组文章数量:1296302
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?
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?
Share Improve this question edited Nov 15, 2016 at 9:43 gabor aron asked Nov 14, 2016 at 14:10 gabor arongabor aron 4102 gold badges4 silver badges19 bronze badges 1- Check aframe.io/docs/0.8.0/introduction/… – Jaider Commented Jan 20, 2019 at 11:15
2 Answers
Reset to default 3If you are using the cursor ponent:
box.addEventListener('click', function (evt) { // ... });
If you want to use the mouse cursor, try https://www.npmjs./package/aframe-mouse-cursor-ponent
You could create a custom ponent like this;
<script>
AFRAME.registerComponent('clickhandler', {
schema: {
txt: {default:'default'}
},
init: function () {
var data = this.data;
var el = this.el;
el.addEventListener('click', function () {
console.log(data.txt);
});
}
});
</script>
<a-image src="img1.png" clickhandler="txt:image1"></a-image>
<a-box clickhandler="txt:box1"></a-box>
<a-entity cursor="rayOrigin:mouse"></a-entity>
More info here https://aframe.io/docs/1.2.0/core/ponent.html
本文标签: aframeHow to get click event with javascript from an Aframe elementStack Overflow
版权声明:本文标题:aframe - How to get click event with javascript from an A-frame element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741633809a2389521.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论