【问题标题】:Animate in aframe entity on hover悬停时在框架实体中设置动画
【发布时间】:2019-02-21 06:04:26
【问题描述】:

我在 AFRAME 元素/实体中制作动画时遇到问题。在下面的演示中,我设置了一个框,并在框顶部设置了一个文本实体,当我将鼠标悬停在框上时,该文本实体需要动画(放大),文本元素不会动画或显示。有人可以帮忙吗?

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");
    });
  }
});

【问题讨论】:

    标签: aframe


    【解决方案1】:

    这里有两个问题:

    1) 如果您想使用 document.querySelector('#fernando') 获取 fernando - id 需要是 fernando 而不是 #fernando

    2) 组件声明 - 在这种情况下为 activate-name - 需要在组件附加到 html 之前 完成。你可以简单地在场景之前把它扔一个&lt;script&gt;标签

    <script>
      AFRAME.registerComponent('foo', ...
    </script>
    <a-scene>
      <a-entity foo></a-entity>
    </a-scene>
    

    更好 - 将其保存在单独的 .js 文件中,并将其包含在 &lt;head&gt; 中。 小提琴here.


    这是必要的,因为 jsfiddle 在加载窗口时执行代码部分。

    【讨论】:

      猜你喜欢
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      相关资源
      最近更新 更多