我试图使用particles.js作为背景,但我无法将画布设置为全尺寸的背景。
我从类似的问题中尝试了至少10种不同的解决方案,但都没有效果。画布的结果总是像屏幕一样具有宽度-高度比的元素,但当调整尺寸时,它并不作为一个整体覆盖它。在成瘾中,它不会被设定为背景,而是作为身体的一个孩子,超过或低于其余的元素。
我尽可能地简化了代码,问题仍然存在。
HTML
<!DOCTYPE HTML>
<html>
<head>
<title>Try</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" media="screen" href="css/style.css">
</head>
<body>
<div id="particles-js"></div>
<div>
<p>Something here</p>
</div>
</body>
<script src="assets/js/particles.js"></script>
<script src="assets/js/app.js"></script>
</html>CSS
canvas{
display:block;
vertical-align:bottom;
position: absolute;
}
/* ---- particles.js container ---- */
#particles-js{
position: absolute;
width: 100%;
height: 100%;
background-color: #b61924;
background-image: url('');
background-size: cover;
background-position: 50% 50%;
background-repeat: no-repeat;
top: 0;
}APP.JS和PARTICLES.JS可以从之前发布的所有者网站上下载。我正在用他们,因为他们现在
谢谢你的帮助
发布于 2017-07-31 10:55:05
好的,我终于解决了背景问题:这就是我如何管理它(我很肯定我已经尝试过了,但是如果最终成功的话,我会重新构建整个html )。
CSS
#particles-js{
width: 100%;
height: 100%;
position: fixed;
background-color: #000;
background-image: url('');
background-size: cover;
background-position: 50% 50%;
background-repeat: no-repeat;
}
.body-particles{
position: absolute;
top: 0;
left: 0;
z-index: 100;
}HTML
<html>
<head>
<title>Title</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- SOME CSSs HERE -->
<link rel="stylesheet" media="screen" href="assets/css/particles.css">
<!-- SOME SCRIPTS HERE -->
</head>
<body>
<div class="body-particles">
<!-- Wrapper -->
<div id="wrapper">
<!-- MY STUFF HERE, STYLED WITH MY CSS -->
</div>
</div>
<!-- particles.js container -->
<div id="particles-js"></div>
<!-- scripts -->
<script src="assets/js/particles.js"></script>
<script src="assets/js/app.js"></script>
</body>
</html>现在,我有了一个新的问题:作为底层设置,它不会捕获指针事件。一旦我让它起作用,我会更新答案。
显然,如果你有任何建议的话,可以随时提供帮助。
UPDATE: mouseEvents的解决方案:将类mouseEvents添加到我需要关注的元素中(例如,导航条等)
CSS
.body-particles{
pointer-events: none;
}
.mouseEvents{
pointer-events: all;
}然而,如果有人知道一个更好的方法将事件保持在前面和后面的话,那就太好了。
发布于 2019-01-23 15:15:38
我只需要这么做..。
HTML:
<body>
<div id="particles-js"></div>
...
</body>CSS:
#particles-js {
height: 100%;
width: 100%;
position: fixed;
z-index: -100;
}发布于 2017-07-31 00:40:29
假设您试图模仿示例页面,那么我要做的是:
body: {
padding: 0px;
margin: 0px;
}
canvas{
width: 100%;
height: 100%;
}
/* ---- particles.js container ---- */
#particles-js{
position: fixed;
width: 100%;
height: 100%;
z-index: 0;
top: 0px;
left: 0px;
background-color: #b61924;
background-image: url('');
background-size: cover;
background-position: 50% 50%;
background-repeat: no-repeat;
}
.actual-content-container
{
z-index: 100;
/* whatever other style properties you want. Apply this class to the div or other element you put your actual content in.*/
}这基本上就是演示页面的方式。关键是z-index属性。如果您想要的是与实际内容一起滚动的背景,请尝试将粒子-js id的位置元素更改为绝对。我觉得这应该能让你大开眼界。
https://stackoverflow.com/questions/45405463
复制相似问题