【问题标题】:AFRAME Animating in Text on hover issue悬停问题上的 AFRAME 文本动画
【发布时间】:2019-02-25 02:51:08
【问题描述】:

https://jsfiddle.net/ykma6r0d/1/

演示链接 ^

HMTL:

<a-scene>
  <!-- CAMERA CURSOR -->
  <a-entity id="camera" camera mouse-cursor look-controls wasd-controls>
    <a-cursor fuse="true" color="red"></a-cursor>
  </a-entity>
  <a-entity id="myTarget" scale="1 .001 1" look-at="#camera" text="color: black;align: center; value: YAYA!; width: 6; wrap-count: 10" animation__1="startEvents: in;property: scale; dur: 200; from: 1 .001 7; to: 1 1 1" animation__2="startEvents: out;property: scale; dur: 200; from: 1 1 1; to: 1 .001 1"></a-entity>
  <a-circle name-on-hover="target: #myTarget" position="-2 0 -10" material="color: blue" material="opacity:.75" look-at="#camera" animation="property: position;easing: easeInSine;loop:true;dir: alternate;dur: 2000;to:-2 .2 -10">
  </a-circle>
</a-scene>

JS:

AFRAME.registerComponent("name-on-hover", {
  schema: {
    target: {
      type: "selector",
      default: ""
    }
  },
  init: function() {
    var target = this.data.target;
    var el = this.el;
    this.setupNamePos();
    el.addEventListener("mouseenter", function() {
      target.emit("in"); // animate in
    });
    el.addEventListener("mouseleave", function() {
      target.emit("out"); // animate out
    });
  },
  setupNamePos: function() {
    var name = this.data.target; // get name element
    var elPos = this.el.getAttribute("position"); // get the pos of hovered element

    name.setAttribute("position", {
      //set name position relevant to hovered element
      x: elPos.x,
      y: elPos.y + 2,
      z: elPos.z
    });
  }
});

我有两个元素,一个圆圈和一个文本元素

圆形元素:其上方的文本需要在悬停时进行动画处理。在我的 JS 中,我对其进行了设置,以便它抓取圆的位置,然后将该位置设置为我的文本元素,但在此之前它将 Y 位置增加 2 个单位。

由于某种原因,当我将鼠标悬停在圆圈上时,我的动画会疯狂循环。起初我认为这可能是因为文本元素与圆圈重叠,失去了悬停事件。但是我尝试通过修改 X 和 Z 将文本元素移动到不同的位置.. 但没有运气。

【问题讨论】:

    标签: animation text aframe


    【解决方案1】:

    当文本展开时,它会妨碍光标射线投射器 - 并且mouseleave 被发射。

    您可以使用objects 属性限制光标可以单击的实体。

    <a-cursor objects='clickable'> </a-cursor>
    

    小提琴here.

    【讨论】:

    • 完美,成功了!,我希望文档更详细,并提供小示例代码。
    • @user1986245 很高兴我能提供帮助。 docs 中提到了此功能,尽管切换可点击目标的示例可能是个好主意
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 2012-06-18
    • 2011-07-13
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 2013-08-11
    相关资源
    最近更新 更多