我正在尝试使用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 可以从之前发布的车主网站下载。我正在使用他们现在的主题
谢谢你的帮助