Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide an element with A-Frame?

Tags:

aframe

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

Do I need to remove the element from the DOM?

like image 359
David Walsh Avatar asked Aug 29 '16 15:08

David Walsh


3 Answers

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

el.setAttribute("visible",false);
like image 138
ffmaer Avatar answered Nov 13 '22 01:11

ffmaer


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

myElement.setAttribute("visible", false)

like image 26
David Walsh Avatar answered Nov 13 '22 03:11

David Walsh


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");
}
like image 1
vt5491 Avatar answered Nov 13 '22 02:11

vt5491