[英]How to get click event with javascript from an A-frame element
更新:您可以使用onclick= function();
在 HTML 中。
例如: <a-box onclick="myFunction()"></a-box>
我想用javascript從A-frame元素中獲取光標的點擊事件,例如一個盒子,我該怎么做?
如果您使用光標組件:
box.addEventListener('click', function (evt) { // ... });
如果要使用鼠標光標,請嘗試https://www.npmjs.com/package/aframe-mouse-cursor-component
你可以像這樣創建一個自定義組件;
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.