我一直在 mouseenter 上调用 javascript 函数,如下所示:
document.querySelector('a-cylinder').addEventListener('mouseenter', function(evt) {
alert("This is a cylinder.");
})
document.querySelector('a-box').addEventListener('mouseenter', function(evt) {
alert("This is a box.");
})
document.querySelector('testBox').addEventListener('mouseenter', function(evt) {
alert("This is a box, targeted with an ID");
})
<script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-event-set-component@3.0.3/dist/aframe-event-set-component.min.js"></script>
<a-scene>
<a-camera camera look-controls="reverseMouseDrag: true" cursor="rayOrigin: mouse" raycaster="objects: .hoverable"></a-camera>
<a-box class="hoverable" position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
<a-box id="testBox" class="hoverable" position="0 0.8 -4" rotation="0 45 0" radius="1.25" color="#EF2D5E"></a-box>
<a-cylinder class="hoverable" position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
它适用于圆柱体和第一个框(HTML 中的第一个框)。但是,我无法指定要悬停在哪个框上来调用该函数,而不是使用querySelector('a-box')
I use querySelector('elementID')
。