悬停问题上的文本动画 AFRAME
AFRAME Animating in Text on hover issue
https://jsfiddle.net/ykma6r0d/1/
Link 演示 ^
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 将文本元素移动到不同的位置。但是没有成功。
当文本展开时,它会妨碍光标光线投射器 - 并且 mouseleave
会被发射。
您可以使用 objects
属性.
限制光标可以单击的实体
<a-cursor objects='clickable'> </a-cursor>
fiddle here.
https://jsfiddle.net/ykma6r0d/1/
Link 演示 ^
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 将文本元素移动到不同的位置。但是没有成功。
当文本展开时,它会妨碍光标光线投射器 - 并且 mouseleave
会被发射。
您可以使用 objects
属性.
<a-cursor objects='clickable'> </a-cursor>
fiddle here.