最近做了一個(gè)PC站首頁(yè)demo,為了讓頁(yè)面不至于太死板粥诫,在背景上給一些模塊加入了這種粒子效果油航,
移動(dòng)端demo:https://lavendergirl.github.io/particles/mobile-index.html
PC端demo:https://lavendergirl.github.io/particles/index.html
線上test:https://codepen.io/VincentGarreau/pen/pnlso
如果需要看源碼實(shí)現(xiàn)可以在github上看看:https://github.com/lavenderGirl/particles
具體實(shí)現(xiàn):
<!-- 當(dāng)然在使用的時(shí)候得先引用particles.js -->
<div class="particles container">
<div id="particles-js"></div>
</div>
<div class="particles overlay"></div>
<!-- js這樣去配置就行了 -->
particlesJS('particles-js',{
"particles": {
"number": {
"value": 100,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {
"value": "#3a7ee4"
},
"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": 5,
"random": false,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 300,
"color": "#3a7ee4",
"opacity": 0.4,
"width": 1
},
"move": {
"enable": true,
"speed": 3,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": true,
"mode": "repulse"
},
"onclick": {
"enable": true,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 400,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true,
"config_demo": {
"hide_card": false,
"background_color": "#b61924",
"background_image": "",
"background_position": "50% 50%",
"background_repeat": "no-repeat",
"background_size": "cover"
}
});
配置可參考:https://www.cnblogs.com/wangyihong/p/8618305.html
當(dāng)然也可直接看 https://github.com/VincentGarreau/particles.js
通過(guò)不同的配置可以實(shí)現(xiàn)很多不一樣的效果哦。動(dòng)手去試試吧怀浆。
沒(méi)做這個(gè)之前谊囚,都不知道這叫什么怕享,只知道有時(shí)候會(huì)在一些網(wǎng)站上看到,也沒(méi)太注意镰踏,真正想要用的時(shí)候函筋,不知道去搜什么,所在在找的過(guò)程中也花了一點(diǎn)時(shí)間奠伪,如果你也需要這種效果跌帐,那么這篇文章適合你看看哦。
不是每一次努力都有收獲绊率,但是谨敛,每一次收獲都必須努力。加油滤否。