在網頁中使用particlesjs實現背景的動態粒子特效

來源:互聯網
上載者:User

標籤:rem   logs   檔案   aaa   動態   retina   eve   hover   com   

先上一張:

 

這種動態背景特效,製作起來其實非常簡單。

 

使用了particles.js

particles.js可以從github網站下載到最新的源碼,網址是 https://github.com/VincentGarreau/particles.js/

 

使用方法非常簡單

第一步,在html中引入指令檔 particles.min.js,這個檔案在下載的壓縮包裡可以找到

<script src="particles.min.js"></script>

 

第二步,在html中放入一個div容器,設定id為particles-js。這個一般放在所有網頁元素的最後面就可以。

<div id="particles-js"></div>
<style type="text/css">
  #particles-js {
    position: absolute;
    top:0;
    width:100%;
  }
</style>

 

第三步,設定視窗樣式

<style type="text/css">
  #particles-js {
    z-index: -1;
    position: absolute;
    top: 0;
    width: 100%;
    background: #aaa;
  }</style>

 

第四步,指令碼產生粒子效果,可以單獨放在一個js檔案裡,也可以放在<script>標籤裡。無論如何,這段指令碼要出現在div容器之後。

particlesJS("particles-js", {  "particles": {    "number": {      "value": 380,      "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": 3,      "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",      "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});

 

完工。

在網頁中使用particlesjs實現背景的動態粒子特效

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.