最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Possible to put HTML Content on top of a Canvas (Landing Page) - Stack Overflow

programmeradmin3浏览0评论

I have a canvas setup with a number of particles that move around the screen. When the user clicks more particles get added. The problem is, this particle system is for a landing page.

I have the canvas working, however If I want to add text to the landing page, I can't. Is this possible? I would like to have "Wele" in the center of the screen however if I add it into the HTML code where the particles are, It is not visible.

---My HTML---

<div id="particles-js"></div>
<div class="count-particles">
  <span class="js-count-particles">--</span> particles
</div>

---The 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;
}

I have a Codepen.io setup, ANY help is much appreciated!

-Codepen.io -

I have a canvas setup with a number of particles that move around the screen. When the user clicks more particles get added. The problem is, this particle system is for a landing page.

I have the canvas working, however If I want to add text to the landing page, I can't. Is this possible? I would like to have "Wele" in the center of the screen however if I add it into the HTML code where the particles are, It is not visible.

---My HTML---

<div id="particles-js"></div>
<div class="count-particles">
  <span class="js-count-particles">--</span> particles
</div>

---The 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;
}

I have a Codepen.io setup, ANY help is much appreciated!

-Codepen.io - http://codepen.io/HoneyBadgerYT/pen/jqKZxo

Share Improve this question asked Apr 20, 2016 at 9:10 mp.jpegmp.jpeg 1973 silver badges18 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

you can do this with css

h1 {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
}

html:

<div id="particles-js"></div>

<h1>Wele</h1>
<div class="count-particles">
  <span class="js-count-particles">--</span> particles
</div>

see working demo

If you add another element (such as an h2 or div) then you will need to give it a position:absolute and a z-index that is higher than the z-index of your #particle-js

see below html:

(notice that I added a z-index property to your #particle-js element, and I also added h2 styling below that.)

<div id="particles-js"></div>
<h2>WELCOME</h2>


<div class="count-particles">
  <span class="js-count-particles">--</span> particles
</div>

and 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;
}

发布评论

评论列表(0)

  1. 暂无评论