我在網上看到一個很炫酷,很有趣的特效,網頁上會有很多移動的粒子和線條,鼠標經過時會以鼠標為中心吸附過來,如果時間夠久,會形成一個類似震動的、帶輻條的車輪子的東西。
網上搜了一下,源碼是github里面的canvas-nest.js插件
github地址:https://github.com/hustcc/canvas-nest.js
使用也很簡單,html上引入插件js就行了,代碼如下:
<script type="text/javascript" color="255,0,255" pointColor="255,0,255" opacity='0.7' zIndex="-2" count="100" src="dist/canvas-nest.js"></script>
官方給的配置說明
Configuration
color: color of lines, default: '0,0,0'; RGB values: (R,G,B).(note: use ',' to separate.)
pointColor: color of points, default: '0,0,0'; RGB values: (R,G,B).(note: use ',' to separate.)
opacity: the opacity of line (0~1), default: 0.5.
count: the number of lines, default: 99.
zIndex: z-index property of the background, default: -1.
經我試驗,大概是這樣的:
color:線條顏色,默認是(0,0,0),格式是(R,G,B)
pointColor:粒子顏色,這個應該是線條連接的點的顏色,默認是(0,0,0),格式是(R,G,B)
opacity:透明度(0-1),默認0.5
count:線段的數量,默認0.5,設置的過多的時候頁面打開會變慢,我設置10000,打開要好幾秒,頁面上的線條直接變成一坨了,也不會動了,O(∩_∩)O哈哈~
zIndex:Z-index參數,默認-1
done!