分享
也是一种美德

给网站背景添加随鼠标变幻的特效Canvas-Nest

这是一个基于 canvas 绘制的光标线条粒子组合动态网页背景效果。这个特效使用非常方便,使用原生的 javascript,不依赖任何框架或者内库,包括不依赖 jQuery,非常容易实现

效果图:

背景图

实现的方法有两种

第一种:直接写进代码

!function(){function n(n,e,t){return n.getAttribute(e)||t}function e(n){return document.getElementsByTagName(n)}function t(){var t=e(“script”),o=t.length,i=t[o-1];return{l:o,z:n(i,“zIndex”,-1),o:n(i,“opacity”,.5),c:n(i,“color”,“0,0,0”),n:n(i,“count”,99)}}function o(){a=m.width=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,c=m.height=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}function i(){r.clearRect(0,0,a,c);var n,e,t,o,m,l;s.forEach(function(i,x){for(i.x+=i.xa,i.y+=i.ya,i.xa*=i.x>a||i.x<0?-1:1,i.ya*=i.y>c||i.y<0?-1:1,r.fillRect(i.x-.5,i.y-.5,1,1),e=x+1;e<u.length;e++)n=u[e],null!==n.x&&null!==n.y&&(o=i.x-n.x,m=i.y-n.y,l=o*o+m*m,l<n.max&&(n===y&&l>=n.max/2&&(i.x-=.03*o,i.y-=.03*m),t=(n.max-l)/n.max,r.beginPath(),r.lineWidth=t/2,r.strokeStyle=“rgba(“+d.c+“,”+(t+.2)+“)”,r.moveTo(i.x,i.y),r.lineTo(n.x,n.y),r.stroke()))}),x(i)}var a,c,u,m=document.createElement(“canvas”),d=t(),l=“c_n”+d.l,r=m.getContext(“2d”),x=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(n){window.setTimeout(n,1e3/45)},w=Math.random,y={x:null,y:null,max:2e4};m.id=l,m.style.cssText=“position:fixed;top:0;left:0;z-index:”+d.z+“;opacity:”+d.o,e(“body”)[0].appendChild(m),o(),window.onresize=o,window.onmousemove=function(n){n=n||window.event,y.x=n.clientX,y.y=n.clientY},window.onmouseout=function(){y.x=null,y.y=null};for(var s=[],f=0;d.n>f;f++){var h=w()*a,g=w()*c,v=2*w()-1,p=2*w()-1;s.push({x:h,y:g,xa:v,ya:p,max:6e3})}u=s.concat([y]),setTimeout(function(){i()},100)}();

第二种:利用插件实现后台搜索Canvas-Nest.js插件,安装并启用就可以了

赞(1) 打赏
未经允许不得转载:宇峰博客 » 给网站背景添加随鼠标变幻的特效Canvas-Nest
分享到: 更多 (0)

评论 26

  1. #1

    Cialis Without Prescriptions Viagra 25 Prix En Limoges cialis Prednisolone

    匿名2个月前 (04-30)回复
  2. #2

    Mexico Pharmacy Ou Acheter Cialis Serieux Buy Propecia 5mg Usa canadian pharmacy cialis Permethrin Cream Comparison Viagra Cialis Buy Kamagra Lione

    匿名2个月前 (04-30)回复
  3. #3

    Diges Tea cialis 5mg Cialis Packungsbeilage Amoxil Side Effects In Dogs

    匿名2个月前 (04-30)回复
  4. #4

    Metronidazole 200mg Sale Montreal The Antibiotic Cephalexin cialis Cialis 10 Mg Efectos Viagra Natur

    匿名1个月前 (05-05)回复
  5. #5

    Md Price Pharmacy Discounts Moltrin 800 For Sale Order Doxycycline cialis overnight shipping from usa Levitra Posologia Di

    匿名1个月前 (05-09)回复
  6. #6

    Levitra Quotazione Farmacia Medicine Without Perscription Problemas De Propecia cialis vs viagra Que Espana La Propecia

    匿名1个月前 (05-13)回复
  7. #7

    Ordonnance Tadalis Sx Soft Singapour proscar Viagra Preiswert

    匿名1个月前 (05-16)回复
  8. #8

    Medicament Cytotec Sans Ordonnance Brand Cialis Best Price levitra 20mg prix Discount isotretinoin Funciona Propecia Amoxicillin Crohn’S

    匿名2周前 (06-02)回复
  9. #9

    Achat Amoxicillin Pilule Pharmacie Patch Et Nazaire online cialis Zithromax Mexico

    匿名2周前 (06-04)回复
  10. #10

    Accutaine buy alli refill pills online Cialis 20 Mg Indicazioni Propecia Con Como Hacer 50 Mil Viagra

    匿名1周前 (06-06)回复
  11. #11

    Kamagra With Food Propecia Fa Crescere Dei Capelli Viagra Sales Las Vegas cialis canada Keflex For Gum Infection

    匿名1周前 (06-07)回复
  12. #12

    Viagra Kaufen Bewertung cheapest cialis Propecia Cost Online Cialis Farmacias Online

    匿名1周前 (06-07)回复
  13. #13

    500mg Penicillin For Std To Buy Zithromax And Sun Exposure cialis with priligy pills Cialis 200 Mg India

    匿名1周前 (06-07)回复
  14. #14

    Levitra Moins Cher En Ligne viagra Levitra Comprimes Lexapro Brand Online Where To Buy Viagra In Los Angeles

    匿名1周前 (06-09)回复
  15. #15

    Pharmacy Prices For Levitra cialis 5 mg best price usa Cheap Plavix Propecia Es Peligroso

    匿名7天前回复
  16. #16

    Synthese Levitra Commander Du Viagra En Belgique Cialis 20mg Filmtabletten Import Reimport online pharmacy Can Amoxicillin Cause Hypoglycemia

    匿名7天前回复
  17. #17

    Viagra Ohne Rezept In Berlin Best Cheapest Way To Get Cialis Kamagra 100mg Gold cialis 5mg best price Doxycycline Buy Online Reviews

    匿名6天前回复
  18. #18

    Discount Amoxicilina With Next Day Delivery levitra on line Sertraline Overdose Low Cost Propecia Levitra Effetti Collaterali In Farmacia

    匿名6天前回复
  19. #19

    Why Use Keflex Port Vila cialis viagra levitra kaufen rezeptfrei Bactrim Roche Il Viagra A 20 Anni Ficha Tecnica De Propecia

    匿名6天前回复
  20. #20

    Isotretinoin generic 5mg cialis best price Propecia Oferta Farmacia

    匿名5天前回复
  21. #21

    Ciprofloxacin 500mg Buy Online Safe Propecia Merck Active Ingredient viagra france paypal How Much Is A Viagra Prescription Achat Viagra Pilules Achat Amoxicillin Sens Ordonnance Gratuit Comprime

    匿名5天前回复
  22. #22

    Amoxicillin Alternatives Comprar Viagra Original viagra Cialis Shopping Canadian Drugs No Prescription

    匿名4天前回复
  23. #23

    Get Cheap Cialis Online Cheap Viagra India Vendo Cialis Napoli cialis price Overnight Femara Canadian Buy Nexium Capsules Online Clomid Apres Ovulation

    匿名4天前回复
  24. #24

    Viagra Cialis Douleurs cialis online Kamagra 200mg Oral Jelly Tadacip Order Online Free Propecia Samples

    匿名4天前回复
  25. #25

    Amoxicillin 250 5 Infant Dosage cialis Cialis Farmacia Sin Receta Donde Puedo Comprar Redustat Orlistat

    匿名2天前回复
  26. #26

    Permanent Problems Of Propecia Is Keflex A Beta finasteride Propecia Generique Finasteride Zithromax Medscape Comprar Cialis Internet

    匿名1天前回复

宇峰博客 分享也是一种美德

我的微博我的博客

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏