【发布时间】:2020-03-31 23:08:08
【问题描述】:
我一直在寻找一种简单有效的方法来将单个渐变应用到来自particles.js 库的移动粒子。理想情况下,我想要只使用 CSS 的东西,但我现在很确定即使我已经阅读了关于剪辑路径的有趣内容,例如 explanations on clipping and masking using CSS。
我的目标是做出这样的动态(我除了 Asesprite 没有真正的版本软件,请不要怪我,如果你知道一个好的 linux 矢量工具,告诉我):
要查看该库的实现,请查看demo on CodePen。
我不使用带有particle.js 的服务器(也可以使用there (GitHub),所以我想要一个可以在链接到我的.html 文件的app.js 文件上实现的解决方案:
/* ---- particles.js config ---- */
// default shape: circles
particlesJS("particles-js", {
"particles": {
"number": {
"value": 80,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "stroke",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "../img/particle.png",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 0.5,
"random": true,
"anim": {
"enable": true,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 3,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 180,
"color": "#ffffff",
"opacity": 0.8,
"width": 2
},
"move": {
"enable": true,
"speed": 6,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": true,
"mode": "repulse"
},
"onclick": {
"enable": false,
"mode": "bubble"
},
"resize": true
},
"modes": {
"grab": {
"distance": 140,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 90,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
});
我知道有类似的问题,但我不明白如何设法使粒子充当后面固定梯度的过滤器: a similar case, another one.
【问题讨论】:
标签: javascript css html5-canvas gradient