悬停时在框架实体中设置动画
Animate in aframe entity on hover
我在 AFRAME 中制作动画时遇到问题 element/entities。在下面的演示中,我设置了一个框,并在框的顶部设置了一个文本实体,当我将鼠标悬停在框上时,文本元素不会在其中设置动画或显示。有人可以帮忙吗?
https://jsfiddle.net/0d6ymk21/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://rawgit.com/mayognaise/aframe-mouse-cursor-component/master/dist/aframe-mouse-cursor-component.min.js"></script>
</head>
<body>
<a-scene>
<a-entity id="camera" camera mouse-cursor look-controls>
<a-cursor fuse="true" color="blue"></a-cursor>
</a-entity>
<a-entity
id="#fernando"
text="color: black;value: Fernando;"
scale=".1 .1 .1"
position="2 1 -2"
></a-entity>
<a-box box position="1 0 -2" color="red" activate-name=""></a-box>
</a-scene>
</body>
</html>
-- JS:
AFRAME.registerComponent("activate-name", {
schema: {
default: ""
},
init: function() {
var data = this.data;
var el = this.el;
var fernando = document.querySelector("#fernando");
el.addEventListener("mouseenter", function() {
fernando.setAttribute("scale", "2 2 2");
});
}
});
这里有两个问题:
1) 如果你想使用 document.querySelector('#fernando')
获取 fernando - id 需要是 fernando
而不是 #fernando
.
2) 组件声明 - 在本例中为 activate-name
- 需要在 之前 将组件附加到 html 中。你可以简单地在场景
之前给它一个<script>
标签
<script>
AFRAME.registerComponent('foo', ...
</script>
<a-scene>
<a-entity foo></a-entity>
</a-scene>
更好 - 将其保存在单独的 .js
文件中并将其包含在 <head>
中。
Fiddle here.
这是必要的,因为 jsfiddle 在加载 window 时执行代码部分。
我在 AFRAME 中制作动画时遇到问题 element/entities。在下面的演示中,我设置了一个框,并在框的顶部设置了一个文本实体,当我将鼠标悬停在框上时,文本元素不会在其中设置动画或显示。有人可以帮忙吗?
https://jsfiddle.net/0d6ymk21/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script src="https://rawgit.com/mayognaise/aframe-mouse-cursor-component/master/dist/aframe-mouse-cursor-component.min.js"></script>
</head>
<body>
<a-scene>
<a-entity id="camera" camera mouse-cursor look-controls>
<a-cursor fuse="true" color="blue"></a-cursor>
</a-entity>
<a-entity
id="#fernando"
text="color: black;value: Fernando;"
scale=".1 .1 .1"
position="2 1 -2"
></a-entity>
<a-box box position="1 0 -2" color="red" activate-name=""></a-box>
</a-scene>
</body>
</html>
-- JS:
AFRAME.registerComponent("activate-name", {
schema: {
default: ""
},
init: function() {
var data = this.data;
var el = this.el;
var fernando = document.querySelector("#fernando");
el.addEventListener("mouseenter", function() {
fernando.setAttribute("scale", "2 2 2");
});
}
});
这里有两个问题:
1) 如果你想使用 document.querySelector('#fernando')
获取 fernando - id 需要是 fernando
而不是 #fernando
.
2) 组件声明 - 在本例中为 activate-name
- 需要在 之前 将组件附加到 html 中。你可以简单地在场景
<script>
标签
<script>
AFRAME.registerComponent('foo', ...
</script>
<a-scene>
<a-entity foo></a-entity>
</a-scene>
更好 - 将其保存在单独的 .js
文件中并将其包含在 <head>
中。
Fiddle here.
这是必要的,因为 jsfiddle 在加载 window 时执行代码部分。