mp.*_*peg 4 html javascript css jquery
我有一个画布设置,其中包含许多在屏幕上移动的粒子。当用户单击时,将添加更多粒子。问题是,此粒子系统用于登录页面。
我正在使用画布,但是如果要向登录页面添加文本,则不能。这可能吗?我想在屏幕中央显示“欢迎”,但是如果我将其添加到粒子所在的HTML代码中,则它是不可见的。
-我的HTML--
<div id="particles-js"></div>
<div class="count-particles">
<span class="js-count-particles">--</span> particles
</div>
Run Code Online (Sandbox Code Playgroud)
--- CSS ---
/* ---- reset ---- */
body {
margin: 0;
font:normal 75% Arial, Helvetica, sans-serif;
}
canvas {
display: block;
vertical-align: bottom;
}
/* ---- particles.js container ---- */
#particles-js {
position: absolute;
width: 100%;
height: 100%;
background-color: blue;
background-image: url("");
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}
/* ---- stats.js ---- */
.count-particles{
background: #000022;
position: absolute;
top: 48px;
left: 0;
width: 80px;
color: #13E8E9;
font-size: .8em;
text-align: left;
text-indent: 4px;
line-height: 14px;
padding-bottom: 2px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
}
.js-count-particles{
font-size: 1.1em;
}
#stats,
.count-particles{
-webkit-user-select: none;
margin-top: 5px;
margin-left: 5px;
}
#stats{
border-radius: 3px 3px 0 0;
overflow: hidden;
}
.count-particles{
border-radius: 0 0 3px 3px;
}
Run Code Online (Sandbox Code Playgroud)
我有一个Codepen.io设置,非常感谢您的帮助!
-Codepen.io- http: //codepen.io/HoneyBadgerYT/pen/jqKZxo
你可以用CSS做到这一点
h1 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
}
Run Code Online (Sandbox Code Playgroud)
的HTML:
<div id="particles-js"></div>
<h1>Welcome</h1>
<div class="count-particles">
<span class="js-count-particles">--</span> particles
</div>
Run Code Online (Sandbox Code Playgroud)
观看工作演示
如果您添加另一个元素(例如 h2 或 div),那么您需要给它一个 a ,position:absolute并且 az-index高于z-index您的元素#particle-js
见下面的html:
(请注意,我z-index向您的元素添加了一个属性#particle-js,并且还在其下方添加了h2样式。)
<div id="particles-js"></div>
<h2>WELCOME</h2>
<div class="count-particles">
<span class="js-count-particles">--</span> particles
</div>Run Code Online (Sandbox Code Playgroud)
和CSS
/* ---- reset ---- */
body {
margin: 0;
font:normal 75% Arial, Helvetica, sans-serif;
}
canvas {
display: block;
vertical-align: bottom;
}
/* ---- particles.js container ---- */
#particles-js {
position: absolute;
width: 100%;
height: 100%;
background-color: blue;
background-image: url("");
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
z-index:1;
}
h2 {
position:absolute;
z-index:2;
width:100%;
text-align:center;
color:#ffffff;
top:0;
left:0;
}
/* ---- stats.js ---- */
.count-particles{
background: #000022;
position: absolute;
top: 48px;
left: 0;
width: 80px;
color: #13E8E9;
font-size: .8em;
text-align: left;
text-indent: 4px;
line-height: 14px;
padding-bottom: 2px;
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
}
.js-count-particles{
font-size: 1.1em;
}
#stats,
.count-particles{
-webkit-user-select: none;
margin-top: 5px;
margin-left: 5px;
}
#stats{
border-radius: 3px 3px 0 0;
overflow: hidden;
}
.count-particles{
border-radius: 0 0 3px 3px;
}Run Code Online (Sandbox Code Playgroud)