首先在themes/next/source/js/src里面建一个叫fireworks.js的文件,代码如下:

"use strict";function updateCoords(e){pointerX=(e.clientX||e.touches[0].clientX)-canvasEl.getBoundingClientRect().left,pointerY=e.clientY||e.touches[0].clientY-canvasEl.getBoundingClientRect().top}function setParticuleDirection(e){var t=anime.random(0,360)*Math.PI/180,a=anime.random(50,180),n=[-1,1][anime.random(0,1)]*a;return{x:e.x+n*Math.cos(t),y:e.y+n*Math.sin(t)}}function createParticule(e,t){var a={};return a.x=e,a.y=t,a.color=colors[anime.random(0,colors.length-1)],a.radius=anime.random(16,32),a.endPos=setParticuleDirection(a),a.draw=function(){ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.fillStyle=a.color,ctx.fill()},a}function createCircle(e,t){var a={};return a.x=e,a.y=t,a.color="#F00",a.radius=0.1,a.alpha=0.5,a.lineWidth=6,a.draw=function(){ctx.globalAlpha=a.alpha,ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.lineWidth=a.lineWidth,ctx.strokeStyle=a.color,ctx.stroke(),ctx.globalAlpha=1},a}function renderParticule(e){for(var t=0;t<e.animatables.length;t++){e.animatables[t].target.draw()}}function animateParticules(e,t){for(var a=createCircle(e,t),n=[],i=0;i<numberOfParticules;i++){n.push(createParticule(e,t))}anime.timeline().add({targets:n,x:function(e){return e.endPos.x},y:function(e){return e.endPos.y},radius:0.1,duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule}).add({targets:a,radius:anime.random(80,160),lineWidth:0,alpha:{value:0,easing:"linear",duration:anime.random(600,800)},duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule,offset:0})}function debounce(e,t){var a;return function(){var n=this,i=arguments;clearTimeout(a),a=setTimeout(function(){e.apply(n,i)},t)}}var canvasEl=document.querySelector(".fireworks");if(canvasEl){var ctx=canvasEl.getContext("2d"),numberOfParticules=30,pointerX=0,pointerY=0,tap="mousedown",colors=["#FF1461","#18FF92","#5A87FF","#FBF38C"],setCanvasSize=debounce(function(){canvasEl.width=2*window.innerWidth,canvasEl.height=2*window.innerHeight,canvasEl.style.width=window.innerWidth+"px",canvasEl.style.height=window.innerHeight+"px",canvasEl.getContext("2d").scale(2,2)},500),render=anime({duration:1/0,update:function(){ctx.clearRect(0,0,canvasEl.width,canvasEl.height)}});document.addEventListener(tap,function(e){"sidebar"!==e.target.id&&"toggle-sidebar"!==e.target.id&&"A"!==e.target.nodeName&&"IMG"!==e.target.nodeName&&(render.play(),updateCoords(e),animateParticules(pointerX,pointerY))},!1),setCanvasSize(),window.addEventListener("resize",setCanvasSize,!1)}"use strict";function updateCoords(e){pointerX=(e.clientX||e.touches[0].clientX)-canvasEl.getBoundingClientRect().left,pointerY=e.clientY||e.touches[0].clientY-canvasEl.getBoundingClientRect().top}function setParticuleDirection(e){var t=anime.random(0,360)*Math.PI/180,a=anime.random(50,180),n=[-1,1][anime.random(0,1)]*a;return{x:e.x+n*Math.cos(t),y:e.y+n*Math.sin(t)}}function createParticule(e,t){var a={};return a.x=e,a.y=t,a.color=colors[anime.random(0,colors.length-1)],a.radius=anime.random(16,32),a.endPos=setParticuleDirection(a),a.draw=function(){ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.fillStyle=a.color,ctx.fill()},a}function createCircle(e,t){var a={};return a.x=e,a.y=t,a.color="#F00",a.radius=0.1,a.alpha=0.5,a.lineWidth=6,a.draw=function(){ctx.globalAlpha=a.alpha,ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.lineWidth=a.lineWidth,ctx.strokeStyle=a.color,ctx.stroke(),ctx.globalAlpha=1},a}function renderParticule(e){for(var t=0;t<e.animatables.length;t++){e.animatables[t].target.draw()}}function animateParticules(e,t){for(var a=createCircle(e,t),n=[],i=0;i<numberOfParticules;i++){n.push(createParticule(e,t))}anime.timeline().add({targets:n,x:function(e){return e.endPos.x},y:function(e){return e.endPos.y},radius:0.1,duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule}).add({targets:a,radius:anime.random(80,160),lineWidth:0,alpha:{value:0,easing:"linear",duration:anime.random(600,800)},duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule,offset:0})}function debounce(e,t){var a;return function(){var n=this,i=arguments;clearTimeout(a),a=setTimeout(function(){e.apply(n,i)},t)}}var canvasEl=document.querySelector(".fireworks");if(canvasEl){var ctx=canvasEl.getContext("2d"),numberOfParticules=30,pointerX=0,pointerY=0,tap="mousedown",colors=["#FF1461","#18FF92","#5A87FF","#FBF38C"],setCanvasSize=debounce(function(){canvasEl.width=2*window.innerWidth,canvasEl.height=2*window.innerHeight,canvasEl.style.width=window.innerWidth+"px",canvasEl.style.height=window.innerHeight+"px",canvasEl.getContext("2d").scale(2,2)},500),render=anime({duration:1/0,update:function(){ctx.clearRect(0,0,canvasEl.width,canvasEl.height)}});document.addEventListener(tap,function(e){"sidebar"!==e.target.id&&"toggle-sidebar"!==e.target.id&&"A"!==e.target.nodeName&&"IMG"!==e.target.nodeName&&(render.play(),updateCoords(e),animateParticules(pointerX,pointerY))},!1),setCanvasSize(),window.addEventListener("resize",setCanvasSize,!1)};

打开themes/next/layout/_layout.swig,在</body>上面写下如下代码:

{% if theme.fireworks %}<canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas> <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> <script type="text/javascript" src="/js/src/fireworks.js"></script>
{% endif %}

打开主题配置文件,在里面最后写下:

# Fireworks
fireworks: true

作者:Moorez
链接:https://www.jianshu.com/p/f054333ac9e6
來源:简书

hexo添加点击爆炸效果 duang duang duang相关推荐

  1. Hexo NexT主题添加点击爱心效果

    给NexT主题内添加页面点击出现爱心的效果 创建js文件 在/themes/next/source/js/src下新建文件clicklove.js,接着把该链接下的代码拷贝粘贴到clicklove.j ...

  2. jQuery 打气球小游戏 点击气球爆炸效果

    最近在学习前端,看到偶尔看到前端小游戏,就想自己写一个小游戏,奈何水平有限,只能写打气球这种简单的,所有的气球都是动态生成的,气球的颜色也是随机的 html部分 <div class=" ...

  3. 鼠标点击烟花爆炸效果

    鼠标点击烟花爆炸效果 效果预览: 预览结果 一. 快速使用(引用我创建好的anime.min.js文件) <canvas class="fireworks"style=&qu ...

  4. Android 粒子爆炸效果,可以给任意 view 添加该效果

    ViewExplosion 项目地址:835127729/ViewExplosion 简介:Android 粒子爆炸效果,可以给任意 view 添加该效果 更多:作者   提 Bug   官网    ...

  5. Android之给ImageView添加点击效果

    1 问题 给ImageView添加点击效果 2 解决办法 1).新建selector.xml文件 <?xml version="1.0" encoding="utf ...

  6. 给div添加点击效果

    给div添加点击效果 .item {background: #FFF; } .item:active {background: #F0F0F0; }

  7. JS实现鼠标点击处烟花爆炸效果

    JS实现鼠标点击处烟花爆炸效果(面向对象版) 程序由网上开源"JS实现放烟花效果"代码改编,实现在鼠标点击处出现烟花爆炸效果. 改编前 源码link https://github. ...

  8. 给页面添加图片点击放大效果

    网站图片前端显示可能较小,添加一个点击放大效果方便图片的查看.采用zoom.js 地址:https://fat.github.io/zoom.js GitHub:https://github.com/ ...

  9. android水波纹加光圈扩散效果,swift UIView优雅的添加点击事件 android Material Design 水波纹扩散效果...

    效果图: image 使用方式 UIView,UIImageView,UIButton 一样 let mView = MView() //是否开启水波纹效果,默认开启 mView.rippleEnab ...

最新文章

  1. appium获取元素节点的方法_Appium学废系列(四) 如何写出优雅又健壮的脚本
  2. 在Notes客户端如何打开隐藏视图
  3. 使用Struts2防止表单重复提交
  4. 《Java从小白到大牛》之第9章 字符串
  5. 网络嗅探与欺骗(FTP部分)
  6. 实时流处理系统容错机制(一):综述
  7. mysql 设置某个字段等于某个字段_学习记录-第十八天(李玉婷MySQL基础 第12天)...
  8. Windows下 VS2015编译boost1.62
  9. 使用Visual Studio 创建可视Web Part部件
  10. 从Grunt测试Grunt插件
  11. leetcode 100.Same Tree
  12. (86)Verilog HDL:三分频设计
  13. 物联网-移远M26模块OpenCPU开发第1讲
  14. 北大青鸟的班主任好当吗_北大青鸟学校怎么样靠谱吗?
  15. imageview 自定义 android,Android自定义ImageView实现在图片上添加图层效果
  16. 如何创建从硬盘安装的硬像文件
  17. 【Navicat】Navicat:Navicat 导出数据库表为 EXCEL 格式、设计优化数据字典 EXCEL 模板
  18. AndroidX全解析
  19. linux暂停命令 pause_Linux-pause(2)的使用(day10)
  20. linux sox录音时间控制,SOX的一些命令和kaldi使用sox音频数据增强

热门文章

  1. 和自然语言处理有关的英语_自然语言处理对非英语语言的重要性
  2. Excel程序员常用快捷键
  3. 工作经验这样写,面试就有了!
  4. 日语IT词汇及相关业务词汇
  5. iOS中block的详解weakSelf、strongSelf-转自唐巧
  6. PCRF、PCEF、PCC(转帖)
  7. 下一代宽带策略控制系统走向何方?
  8. c语言摄氏度字符,c语言摄氏度与华氏温度如何转换
  9. C语言万年历(n排)
  10. 冷库设计安装前有哪些检查工作