繁体   English   中英

问:在A帧中预期未触发Mouseleave

[英]Q: mouseleave not triggered when expected in A-frame

当用户将鼠标悬停在它们上方时,我试图更改某些动态创建的框实体的颜色。

它们始终在mouseenter上成功更改,但是似乎mouseleave并不总是被触发,因此有时它们保持悬停颜色。

这是我的应用程序的基本版本:

<html>
  <head>
    <script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
    <script>
      const COLOURS = {
        default: '#ff0000',
        hover: '#ffff00'
      };

      const blockMouseEnter = event => {
        event.target.setAttribute('material', 'color', COLOURS.hover);
      };

      const blockMouseLeave = event => {
        event.target.setAttribute('material', 'color', COLOURS.default);
      };

      AFRAME.registerComponent('stacks', {
        init: function() {
          const sceneElement = document.querySelector('a-scene');

          for (var stackHeight = 0; stackHeight < 20; stackHeight++) {
            const block = document.createElement('a-entity');

            block.setAttribute('geometry', {
              primitive: 'box',
              width: 0.5,
              height: 0.5,
              depth: 0.025
            });

            block.setAttribute(
              'position',
              `0 ${stackHeight * 0.5} -5`
            );

            block.setAttribute('material', 'color', COLOURS.default);

            sceneElement.appendChild(block);

            block.addEventListener('mouseenter', blockMouseEnter);
            block.addEventListener('mouseleave', blockMouseLeave);
          }
        }
      });
    </script>
  </head>
  <body>
    <a-scene stacks>
      <a-entity position="1 1.6 1" rotation="0 45 0">
        <a-camera>
          <a-cursor></a-cursor>
        </a-camera>
      </a-entity>
      <a-sky color="#5CC8FA"></a-sky>
    </a-scene>
  </body>
</html>

这是问题的视频 ,那里永远不会有超过黄色的砖块。

有谁知道为什么会这样吗?

应该在A.Frame的主版本中以0.8.2修复。 尝试https://github.com/aframevr/aframe/commit/000e669f8eb242ed7b1fe2ef45c5607d99d46609

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM