问题
Is it possible to add text to a-sphere or a-box ? or may be show a text box on mouse over on a-sphere? I've seen the example in A-frame, but it is not exactly what I want. My idea is to tag a sphere or a box with a text or text box.
回答1:
<script>
AFRAME.registerComponent('hover-text', {
schema: {
value: {default: ''}
},
init: function () {
var data = this.data;
var el = this.el;
el.addEventListener('mouseenter', function () {
el.setAttribute('text', {content: data.content});
});
}
});
</script>
<a-entity hover-text="value: I am hovered."></a-entity>
来源:https://stackoverflow.com/questions/42495751/a-sphere-show-text-on-mouse-over-or-attach-a-text-to-a-sphere