Backgrounds

three.js background

You can make your three.js scene a background of the webpage by:

  • Setting the canvas css to position fixed. You also have to set the z-index to -1 so your scene appears behind the other html elements (like your headings or text).
canvas {
    position: fixed;
    top: 0;
    left: 0;
    z-index: -1;
}

using an iframe

You use an iframe if your JavaScript must integrate with the page and if you have a complex page then you need to make sure none of the JavaScript in your three.js visualization conflict with the JavaScript doing other things in the page.

html
<iframe id="background" src="responsive.html">
    <div>Your content goes here.</div></iframe
>

Style the iframe to fill the window and be in the background except we also need to set border to none since iframes have a border by default.

css
#background {
    position: fixed;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    z-index: -1;
    border: none;
    pointer-events: none;
}