How can I hide an element with A-Frame?

后端 未结 3 523
清酒与你
清酒与你 2021-02-14 21:08

What is the best way to hide an element using A-Frame?

Do I need to remove the element from the DOM?

相关标签:
3条回答
  • 2021-02-14 21:49

    The easiest way to hide an element is the visible attribute:

    myElement.setAttribute("visible", false)

    0 讨论(0)
  • 2021-02-14 21:54
    var el = document.querySelector("#yourElementId");
    
    el.setAttribute("visible",false);
    
    0 讨论(0)
  • 2021-02-14 22:01

    You can also specify it on the a-frame tag itself e.g.:

    <a-image id="hand-overview-chart"
      src="#handOverviewImg" position="3 3 0"
      width="4" height="4" visible="false">
    </a-image>
    

    Of course you'll still need javascript to trap on some event like "mouseenter" to toggle it visible:

    document.querySelector('#myElParentId').addEventListener('mouseenter',myEventHandler); 
    
    myEventHandler: function (evt) {
      let myEl = document.querySelector("#hand-overview-chart");
      myEl.setAttribute("visible","true");
    }
    
    0 讨论(0)
提交回复
热议问题