particles.js使用及配置

particles.js使用及配置css

參考:http://blog.csdn.net/csdn_yudong/article/details/53128570html

這個項目中有提供demo,能夠直接下載這個項目,打開demo裏面的index.html文件,便可看到效果git

html:github

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>particles.js</title>
  <meta name="description" content="particles.js is a lightweight JavaScript library for creating particles.">
  <meta name="author" content="Vincent Garreau" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <link rel="stylesheet" media="screen" href="css/style.css">
</head>
<body>

<div id="particles-js"></div>

<!-- scripts -->
<script src="js/particles.js"></script>
<script src="js/app.js"></script>

</body>
</html>

particles.js 是它的庫,咱們確定是要引入的,app.js 是參數配置文件,咱們也要引入,而 demo 中的 stats.js 就沒有必要引入了。 
style.css 咱們也能夠引入,背景顏色是在css中設置的。web

app.jscanvas

particlesJS('particles-js',
  
  {
    "particles": {
      "number": {
        "value": 80,
        "density": {
          "enable": true,
          "value_area": 800
        }
      },
      "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": 5,
        "random": true,
        "anim": {
          "enable": false,
          "speed": 40,
          "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",
        "attract": {
          "enable": false,
          "rotateX": 600,
          "rotateY": 1200
        }
      }
    },
    "interactivity": {
      "detect_on": "canvas",
      "events": {
        "onhover": {
          "enable": true,
          "mode": "repulse"
        },
        "onclick": {
          "enable": false,
          "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"
    }
  }

);

配置說明:app

鍵值 參數選項/ 說明 實例
particles.number.value number   數量 40
particles.number.density.enable boolean    true / false
particles.number.density.value_area number   區域散佈密度大小 800
particles.color.value

HEX (string) 
RGB (object) 
HSL (object) 
array selection (HEX) 
random (string)dom

原子的顏色ide

"#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 
array selectionsvg

懸停模式 

"grab"     抓取臨近的
"bubble"  泡沫球效果
"repulse"  擊退效果
["grab", "bubble"]
interactivity.events.onclick.enable boolean  點擊效果 true / false
interactivity.events.onclick.mode

string 
array selection

點擊效果模式

"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
相關文章
相關標籤/搜索