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
});
}
});我有两个元素,一个圆圈和一个文本元素
Circle元素:悬停时需要在其上方设置动画的文本。在我的JS中,我将其设置为抓住圆的位置,然后将该位置设置为我的文本元素,但在此之前,它会将Y位置增加2个单位。
由于某些原因,当我将鼠标悬停在圆圈上时,我的动画循环得像疯了一样。起初,我认为这可能是因为文本元素与圆重叠,失去了悬停事件。但是,我也尝试通过修改X和Z将文本元素移动到不同的位置。但没那么走运。
发布于 2019-02-25 02:51:09
当文本扩展时,它会挡住光标光线投射器的方向--然后mouseleave就会发出。
可以使用objects特性限制光标可以单击的图元。
<a-cursor objects='clickable'> </a-cursor>小提琴here。
https://stackoverflow.com/questions/54833577
复制相似问题