gpt4 book ai didi

javascript - 使用粒子插件和背景图像

转载 作者:搜寻专家 更新时间:2023-10-31 08:50:52 25 4
gpt4 key购买 nike

我正在使用带有背景图像的背景粒子插件。并且背景图像应该模糊。但问题是图像中的粒子也变得模糊了。

我的代码如下:

/* ---- particles.js config ---- */

particlesJS("particles-js", {
"particles": {
"number": {
"value": 30,
"density": {
"enable": true,
"value_area": 320
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "img/github.svg",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 2,
"random": true,
"anim": {
"enable": false,
"speed": 25,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#ffffff",
"opacity": 0.4,
"width": 1
},
"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": "grab"
},
"onclick": {
"enable": true,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 140,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
});


/* ---- stats.js config ---- */
canvas {
display: block;
vertical-align: bottom;
}

/* ---- particles.js container ---- */

#particles-js {
position: absolute;
width: 100%;
height: 100%;
background-color: #fff;
background-image: url("https://blackshellmedia.com/wp-content/uploads/2015/03/Commercial-Buildings.jpg");
backdrop-filter: blur(5px);
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
-webkit-filter: blur(4px);
-moz-filter: blur(4px);
-o-filter: blur(4px);
-ms-filter: blur(4px);
filter: blur(4px);
}
<div id="particles-js"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/particlesjs/2.1.0/particles.js" defer="defer"></script>
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>

请查看结果,您可以找到我面临的确切问题。甚至粒子都变得模糊我该如何解决这个问题。

最佳答案

只需将图像移到外面并使用一个伪元素来创建一个单独的层:

/* ---- particles.js config ---- */

particlesJS("particles-js", {
"particles": {
"number": {
"value": 30,
"density": {
"enable": true,
"value_area": 320
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "img/github.svg",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 2,
"random": true,
"anim": {
"enable": false,
"speed": 25,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#ffffff",
"opacity": 0.4,
"width": 1
},
"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": "grab"
},
"onclick": {
"enable": true,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 140,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
});


/* ---- stats.js config ---- */
canvas {
display: block;
vertical-align: bottom;
}


/* ---- particles.js container ---- */

#particles-js {
position: absolute;
width: 100%;
height: 100%;
}

#particles-js:before {
content: "";
position: absolute;
z-index:-1;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url("https://blackshellmedia.com/wp-content/uploads/2015/03/Commercial-Buildings.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
-webkit-filter: blur(4px);
-moz-filter: blur(4px);
-o-filter: blur(4px);
-ms-filter: blur(4px);
filter: blur(4px);
}
<div id="particles-js"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/particlesjs/2.1.0/particles.js" defer="defer"></script>
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>

关于javascript - 使用粒子插件和背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48637604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com