[英]Doesn't work EventListener in a-frame 0.8.2
This code works properly in A-frame 0.8.0. 此代码在A帧0.8.0中正常工作。 But I cannot get camera rotation from EventListner in A-frame 0.8.2.
但是我无法从A帧0.8.2中的EventListner获得相机旋转。 Does anybody have solution?
有人有解决办法吗?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"> </script>
</head>
<body>
<a-scene>
<a-box color="tomato" position="0 0 -5"depth="2" height="4" width="0.5"></a-box>
<a-camera id="camera" ></a-camera>
</a-scene>
<script type="text/javascript">
var target = document.querySelector('[camera]');
target.addEventListener('componentchanged', function(event) {
console.log(target.getAttribute('rotation'));
});
</script>
</body>
</html>
1) you won't grab <a-camera>
with the [camera]
css selector. 1)您不会使用
[camera]
css选择器抓取<a-camera>
。 Instead you should use document.querySelector(a-camera)
. 相反,您应该使用
document.querySelector(a-camera)
。
2) It's better to poll the rotation value in a custom component: 2)最好在自定义组件中轮询旋转值:
AFRAME.registerComponent("foo", {
tick: function() {
console.log(this.el.getAttribute("rotation")
}
})
HTML HTML
<a-camera foo></a-camera>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.