因為自己需要做產品,所以一個好的UI界面也是很重要的,發現這種散射的原子顆粒特效還不錯,就弄了一個
官方github:https://github.com/VincentGarreau/particles.js/
demo制作器,注意可能需要FQ
https://codepen.io/VincentGarreau/pen/pnlso 這個可以把你制作的demo導出
http://vincentgarreau.com/particles.js/這個可以用來嘗試配置不同效果
使用方法
加載particle.js并配置粒子:
index.html
<div id="particles-js"></div><script src="particles.js"></script>
app.js
/* particlesJS.load(@dom-id, @path-json, @callback (optional)); */particlesJS.load('particles-js', 'assets/particles.json', function() { console.log('callback - particles.js config loaded');});particles.json就是主要的配置文件
注意一下文件順序,不然會出現問題
實際demo
<!DOCTYPE html><html ><head> <meta charset="UTF-8"> <title>particles.js</title> <link rel="stylesheet" href="style.css" rel="external nofollow" ></head><body><div id="particles-js"></div></body> <script src='particles.min.js'></script> 這個玩意需要放在下面 <script src="index.js"></script></html>

如有需要下載demo請到QQ群,黑色原子效果很科幻,還不錯
根據css顏色和json配置文件,就打造屬于自己的科幻效果
參數
| 鍵值 | 參數選項/ 說明 | 實例 |
|---|---|---|
particles.number.value | number 數量 | 40 |
particles.number.density.enable | boolean | true / false |
particles.number.density.value_area | number 區域散布密度大小 | 800 |
particles.color.value | HEX (string) 原子的顏色 | "#b61924" {r:182, g:25, b:36} {h:356, s:76, l:41} ["#b61924", "#333333", "999999"] "random" |
particles.shape.type | string array selection 原子的形狀 | "circle" "edge" "triangle" "polygon" "star" "image" ["circle", "triangle", "image"] |
particles.shape.stroke.width | number 原理的寬度 | 2 |
particles.shape.stroke.color | HEX (string) 原子顏色 | "#222222" |
particles.shape.polygon.nb_slides | number 原子的多邊形邊數 | 5 |
particles.shape.image.src | path link svg / png / gif / jpg 原子的圖片可以使用自定義圖片 | "assets/img/yop.svg" "http://mywebsite.com/assets/img/yop.png" |
particles.shape.image.width | number (for aspect ratio) 圖片寬度 | 100 |
particles.shape.image.height | number (for aspect ratio) 圖片高度 | 100 |
particles.opacity.value | number (0 to 1) 不透明度 | 0.75 |
particles.opacity.random | boolean 隨機不透明度 | true / false |
particles.opacity.anim.enable | boolean 漸變動畫 | true / false |
particles.opacity.anim.speed | number 漸變動畫速度 | 3 |
particles.opacity.anim.opacity_min | number (0 to 1) 漸變動畫不透明度 | 0.25 |
particles.opacity.anim.sync | boolean | true / false |
particles.size.value | number 原子大小 | 20 |
particles.size.random | boolean 原子大小隨機 | true / false |
particles.size.anim.enable | boolean 原子漸變 | true / false |
particles.size.anim.speed | number 原子漸變速度 | 3 |
particles.size.anim.size_min | number | 0.25 |
particles.size.anim.sync | boolean | true / false |
particles.line_linked.enable | boolean 連接線 | true / false |
particles.line_linked.distance | number 連接線距離 | 150 |
particles.line_linked.color | HEX (string) 連接線顏色 | #ffffff |
particles.line_linked.opacity | number (0 to 1) 連接線不透明度 | 0.5 |
particles.line_linked.width | number 連接線的寬度 | 1.5 |
particles.move.enable | boolean 原子移動 | true / false |
particles.move.speed | number 原子移動速度 | 4 |
particles.move.direction | string 原子移動方向 | "none" "top" "top-right" "right" "bottom-right" "bottom" "bottom-left" "left" "top-left" |
particles.move.random | boolean 移動隨機方向 | true / false |
particles.move.straight | boolean 直接移動 | true / false |
particles.move.out_mode | string (out of canvas) 是否移動出畫布 | "out" "bounce" |
particles.move.bounce | boolean (between particles) 是否跳動移動 | true / false |
particles.move.attract.enable | boolean 原子之間吸引 | true / false |
particles.move.attract.rotateX | number 原子之間吸引X水平距離 | 3000 |
particles.move.attract.rotateY | number y垂直距離 | 1500 |
interactivity.detect_on | string 原子之間互動檢測 | "canvas", "window" |
interactivity.events.onhover.enable | boolean 懸停 | true / false |
interactivity.events.onhover.mode | string 懸停模式 | "grab" 抓取臨近的"bubble" 泡沫球效果"repulse" 擊退效果["grab", "bubble"] |
interactivity.events.onclick.enable | boolean 點擊效果 | true / false |
interactivity.events.onclick.mode | string 點擊效果模式 | "push" "remove" "bubble" "repulse" ["push", "repulse"] |
interactivity.events.resize | boolean 互動事件調整 | true / false |
interactivity.events.modes.grab.distance | number 原子互動抓取距離 | 100 |
interactivity.events.modes.grab.line_linked.opacity | number (0 to 1) 原子互動抓取距離連線不透明度 | 0.75 |
interactivity.events.modes.bubble.distance | number 原子抓取泡沫效果之間的距離 | 100 |
interactivity.events.modes.bubble.size | number 原子抓取泡沫效果之間的大小 | 40 |
interactivity.events.modes.bubble.duration | number 原子抓取泡沫效果之間的持續事件 (second) | 0.4 |
interactivity.events.modes.repulse.distance | number 擊退效果距離 | 200 |
interactivity.events.modes.repulse.duration | number 擊退效果持續事件 (second) | 1.2 |
interactivity.events.modes.push.particles_nb | number 粒子推出的數量 | 4 |
interactivity.events.modes.push.particles_nb | number | 4 |
retina_detect | boolean | true / false |
總結
以上所述是小編給大家介紹的JS庫之Particles.js中文開發手冊及參數詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答