How can I hide an element with A-Frame?

坚强是说给别人听的谎言 提交于 2019-12-05 23:30:56

问题


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

Do I need to remove the element from the DOM?


回答1:


var el = document.querySelector("#yourElementId");

el.setAttribute("visible",false);



回答2:


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

myElement.setAttribute("visible", false)




回答3:


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");
}


来源:https://stackoverflow.com/questions/39210403/how-can-i-hide-an-element-with-a-frame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!