【发布时间】:2017-10-29 15:49:14
【问题描述】:
我是 A-frame 的新手,如果这是一个非常明显的问题,我深表歉意。 使用带有 javascript 的 A-frame,当事件发生时,我正在更改各种元素的属性(在这种情况下,鼠标悬停在另一个元素上,但我不仅希望能够影响鼠标悬停的元素)。如何为组件内的属性更改设置动画?请看下面我的问题示例,当您凝视蓝色框时,红色框会移动位置。这是一个简单的例子,但这是一个关于如何实现这种行为的更普遍的问题。你可以看到我在头部包含了动画脚本,但在这个使用的例子中,它只用于恒定的行为,我不知道如何动态更新它。我也知道我可以添加到 HTML 中的动画标签,但我不知道如何影响这一点。非常感谢您的任何建议。
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<meta name="description" content="Hello, WebVR! - A-Frame">
<!-- a-frame library -->
<script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
<!-- a-frame animation plugin -->
<script src="scripts/animation.js"></script>
<script>
AFRAME.registerComponent('cursor-listener', {
//initiate
init: function () {
//add behaviour for mouse enter (or gaze enter)
this.el.addEventListener('mouseenter', function (evt) {
var otherBox = document.querySelector('#otherbox');
otherBox.setAttribute('position', '-2 1 -4');
});
}//end initiate
});//end registerComponent
</script>
</head>
<body>
<a-scene>
<a-sky>
</a-sky>
<a-box cursor-listener position="0 1 -4" color="blue">
</a-box>
<a-box id="otherbox" position="-1 1 -4" color="red">
</a-box>
<a-camera>
<a-cursor>
</a-cursor>
</a-camera>
</a-scene>
</body>
</html>
【问题讨论】:
标签: javascript aframe webvr