簡體   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