Zibll子比主题动态背景美化

最近在折腾我的小破站,修改一下排版。觉得纯白背景太过于单调,所以就找了这么一款动态背景。(对暗夜模式不太友好)

把以下代码放入主题后台-自定义代码-HTML代码中

<div id=”bubble”><canvas style=”display: block; position: fixed; top: 0px; left: 0px; z-index: -1;” width=”1920″ height=”28″>

下面这个代码放入主题后台自定义js代码中

class BGBubble{constructor(i){this.defaultOpts={id:””,num:100,start_probability:.1,radius_min:1,radius_max:2,radius_add_min:.3,radius_add_max:.5,opacity_min:.3,opacity_max:.5,opacity_prev_min:.003,opacity_prev_max:.005,light_min:40,light_max:70,is_same_color:!1,background:”#f5f5f5″},”[object Object]”==Object.prototype.toString.call(i)?this.userOpts={…this.defaultOpts,…i}:this.userOpts={…this.defaultOpts,id:i},this.color=this.random(0,360),this.bubbleNum=[],this.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,this.cancelAnimationFrame=window.cancelAnimationFrame||window.mozCancelAnimationFrame}random(i,t){return Math.random()*(t-i)+i}initBubble(i,t){const a=window.innerWidth,s=window.innerHeight,n=this.userOpts,e=this.random(n.light_min,n.light_max);this.bubble={x:this.random(0,a),y:this.random(0,s),radius:this.random(n.radius_min,n.radius_max),radiusChange:this.random(n.radius_add_min,n.radius_add_max),opacity:this.random(n.opacity_min,n.opacity_max),opacityChange:this.random(n.opacity_prev_min,n.opacity_prev_max),light:e,color:`hsl(${t?i:this.random(0,360)},100%,${e}%)`}}bubbling(i,t,a){!this.bubble&&this.initBubble(t,a);const s=this.bubble;i.fillStyle=s.color,i.globalAlpha=s.opacity,i.beginPath(),i.arc(s.x,s.y,s.radius,0,2*Math.PI,!0),i.closePath(),i.fill(),i.globalAlpha=1,s.opacity-=s.opacityChange,s.radius+=s.radiusChange,s.opacity<=0&&this.initBubble(t,a)}createCanvas(){this.canvas=document.createElement(“canvas”),this.ctx=this.canvas.getContext(“2d”),this.canvas.style.display=”block”,this.canvas.width=window.innerWidth,this.canvas.height=window.innerHeight,this.canvas.style.position=”fixed”,this.canvas.style.top=”0″,this.canvas.style.left=”0″,this.canvas.style.zIndex=”-1″,document.getElementById(this.userOpts.id).appendChild(this.canvas),window.onresize=(()=>{this.canvas.width=window.innerWidth,this.canvas.height=window.innerHeight})}start(){const i=window.innerWidth,t=window.innerHeight;this.color+=.1,this.ctx.fillStyle=this.defaultOpts.background,this.ctx.fillRect(0,0,i,t),this.bubbleNum.length<this.userOpts.num&&Math.random()<this.userOpts.start_probability&&this.bubbleNum.push(new BGBubble),this.bubbleNum.forEach(i=>

i.bubbling(this.ctx,this.color,this.userOpts.is_same_color));const a=this.requestAnimationFrame;this.myReq=a(()=>this.start())}destory(){(0,this.cancelAnimationFrame)(this.myReq),window.onresize=null}}const bubbleDemo=new BGBubble(“bubble”);bubbleDemo.createCanvas(),bubbleDemo.start();

以上就是全部教程咯!修改完记得保存!图片[1]-Zibll子比主题动态背景美化-朝晞小屋

文章版权声明 1、本网站名称:朝晞小屋
2、本站永久网址:https://www.zxiyun.com/
3、更多有趣网站:http://dh.zxiyun.com/
4、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长QQ2604140139进行删除处理。
5、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
6、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
7、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。

© 版权声明
THE END
喜欢就支持一下吧
点赞15赞赏 分享
评论 共2条

请登录后发表评论