Hi,
I want the canvas, PlayCanvas is rendering to, to overlap a html page with the PlayCanvas background set to transparent so that I can add 3D objects to the html page.
I did search the forum and tried the things indicated. But it doesn’t seem to work.
I tried this in the css:
html {
background-color: transparent;
}
body {
margin: 0;
overflow: auto;
background-color: transparent;
}
canvas {
position: absolute;
top: 0;
left: 0;
background-color: transparent;
}
#top-part {
height: 100vh;
}
my html is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>PlayCanvas Hello Cube</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="./javascript/playcanvas/playcanvas-stable.js"></script>
<script src="./javascript/main.js" defer></script>
</head>
<body>
<canvas id="top-canvas"></canvas>
<div id="top-part">
<h1>Exoleap Main Page</h1>
<nav>
<a href="#">Companies</a>
<a href="book.html">Book</a>
</nav>
<p>Test on main page</p>
</div>
<footer>Copyright © 2023 by Mechamania.</footer>
</body>
</html>
in main.js I start the PlayCanvas. PlayCanvas works and objects are rendered. But background is not transparent.
I also tried to add this in the code:
var bd = document.getElementsByTagName("body")[0];
var ht = document.getElementsByTagName("html")[0];
var cv = document.getElementsByTagName("canvas")[0];
bd.style.backgroundColor = "transparent";
ht.style.backgroundColor = "transparent";
cv.style.backgroundColor = "transparent";
But that also did not work.
The element with the top-part id is not visible. The footer is. So I think the top-part is behind the Playcanvas. But it is not vissible because the PlayCanvas is not transparent.