Currently I have this piece of code running a canvas animation that shows subtle stars moving and sparkling. Currently the canvas is it's own element but I'm wanting to move it to be a background element on a parent div. Can anybody show me how to do this. JS fiddle attached here - https://jsfiddle.net/83aahcng/
目前我有这段代码运行画布动画,显示微妙的星星移动和闪闪发光。目前画布是它自己的元素,但我想将它移动为父div的背景元素。任何人都可以告诉我如何做到这一点。 JS小提琴附在这里 - https://jsfiddle.net/83aahcng/
<div id="container">
<canvas id="pixie"></canvas>
</div>
1 个解决方案
#1
2
I would just put a div over pixie like this... div over pixie.
我会像这样把小精灵放在小精灵身上......溺爱小精灵。
HTML:
<div id="container">
<div id="over_stuff">
Here's some stuff over #pixie!
</div>
<canvas id="pixie"></canvas>
</div>
CSS:
#container {
overflow:hidden;
position:relative;
z-index: 1;
}
#pixie {
z-index:0;
background:#010222;
background:
}
#over_stuff{
color:white;
position:absolute;
top:0px;
left:0px;
z-index:5;
padding:10px;
}
Is there is something I'm not understanding? This seems way too simple
有什么我不理解的吗?这似乎太简单了
#1
2
I would just put a div over pixie like this... div over pixie.
我会像这样把小精灵放在小精灵身上......溺爱小精灵。
HTML:
<div id="container">
<div id="over_stuff">
Here's some stuff over #pixie!
</div>
<canvas id="pixie"></canvas>
</div>
CSS:
#container {
overflow:hidden;
position:relative;
z-index: 1;
}
#pixie {
z-index:0;
background:#010222;
background:
}
#over_stuff{
color:white;
position:absolute;
top:0px;
left:0px;
z-index:5;
padding:10px;
}
Is there is something I'm not understanding? This seems way too simple
有什么我不理解的吗?这似乎太简单了