Menu

A-Frame HTML Embed Component

HTML Embed is a component created for A-Frame. The HTML Embed component allows for arbitrary html to be inserted into your aframe scene. It allows you to update the display within A-Frame simply by manipulating the DOM as you normally would.

In addition to rendering the html to the A-Frame scene it allows for interaction. Most css pseudo selectors such as hover, active, focus and target should work with interactivity enabled without any modifications to your css. Mouse events can be attached to the html elements as usual.

Cascading Style Sheets (CSS)

HTML Embed allows you to add interactivity by adding standard css interactions such as hover:

.button { color: #000000;} .button:hover{ color: #ffffff;}
<a-scene> <a-entity htmlembed> <a href="#home" class="button">Home</a> </a-entity> </a-scene>

Interactivity

You can add javascript interactivity in the standard way either by events on the elements themselves or alternatively by adding event listeners to the DOM.

cubebutton.addEventListener("click",function(){ if(show){ box.setAttribute("visible","false"); cubebutton.innerHTML="Show Box"; }else{ box.setAttribute("visible","true"); cubebutton.innerHTML="Hide Box"; } show=!show; });
Show Box

Limitations

  • All styles and images must be in the same origin or allow access via CORS; this allows the component to embed all of the assets required to render the html properly to the canvas via the foreignObject element.
  • transform-style css is limited to flat. This is mainly due to it not being rendered properly to canvas so element bounding for preserve-3d has not yet been implemented. If the rendering is fixed as some point I may go back and get it working as well.
  • "a-" tags do not render correctly as XHTML embeded into SVG, so any parent "a-" elements of the embed html will be converted to div tags for rendering. This may mean your css will require modification.
  • Elements that require rendering outside of the DOM such as the iframe and canvas element will not work.
  • :before and :after pseudo elements can't be accessed via the DOM so they can't be used in the element to determine the object bounds. As such, use them with caution.
  • Form elements are not consistently rendered to the canvas element so some basic default styles are included for consistency.
  • currently there is no support for css transitions.

Links

this
A-Frame
Github
npm