particles.js是一个轻量级的创建粒子背景的 JS 库,用来在网页上创建颗粒效果。
![]() |
---|
在HTML中包含缩小的JS(就在结束正文标记之前)。
<body>
…
<script src="path/to/particles.min.js"></script>
</body>
将画布元素添加到标记中(它应该是最后一个元素)
<body>
…
<canvas class="background"></canvas>
<script src="path/to/particles.min.js"></script>
</body>
[CSS]
<style>
html,
body {
margin: 0;
padding: 0;
}
.background {
position: absolute;
display: block;
top: 0;
left: 0;
z-index: 0;
}
</style>
window.onload = function() {
Particles.init({
selector: '.background'
});
};
Option | Type | Default | Description |
selector | string | - | Required: The CSS selector of your canvas element |
maxParticles | integer | 100 | Optional: Maximum amount of particles |
sizeVariations | integer | 3 | Optional: Amount of size variations |
speed | integer | 0.5 | Optional: Movement speed of the particles |
color | string or string[] | #000000 | Optional: Color(s) of the particles and connecting lines |
minDistance | integer | 120 | Optional: Distance in px for connecting lines |
connectParticles | boolean | FALSE | Optional: true/false if connecting lines should be drawn or not |
responsive | array | null | Optional: Array of objects containing breakpoints and options |
官网地址 : https://marcbruederlin.github.io/particles.js/
GitHub 地址 :https://gitcode.net/mirrors/VincentGarreau/particles.js?utm_source=csdn_github_accelerator
效果演示 : http://www.tstudy.com.cn/bk.html