solo-skins/Bubble/js/circleMagic.min.js

1 line
6.6 KiB
JavaScript
Raw Normal View History

2019-11-05 12:08:07 +08:00
!function(t){t.fn.circleMagic=function(i){var n,o,s,e,h=!0,a=[],r=t.extend({color:"rgba(255,255,255,.5)",radius:10,density:.3,clearOffset:.2},i),l=this[0];function c(){n=l.clientWidth,o=l.clientHeight,l.height=o+"px",s.width=n,s.height=o}function d(){if(h)for(var t in e.clearRect(0,0,n,o),a)a[t].draw();requestAnimationFrame(d)}function p(){var t=this;function i(){t.pos.x=Math.random()*n,t.pos.y=o+100*Math.random(),t.alpha=.1+Math.random()*r.clearOffset,t.scale=.1+.3*Math.random(),t.speed=Math.random(),"random"===r.color?t.color="rgba("+Math.floor(255*Math.random())+", "+Math.floor(255*Math.random())+", "+Math.floor(255*Math.random())+", "+Math.random().toPrecision(2)+")":t.color=r.color}t.pos={},i(),this.draw=function(){t.alpha<=0&&i(),t.pos.y-=t.speed,t.alpha-=5e-4,e.beginPath(),e.arc(t.pos.x,t.pos.y,t.scale*r.radius,0,2*Math.PI,!1),e.fillStyle=t.color,e.fill(),e.closePath()}}!function(){n=l.offsetWidth,o=l.offsetHeight,t=document.createElement("canvas"),t.id="canvas",l.appendChild(t),t.parentElement.style.overflow="hidden",(s=document.getElementById("canvas")).width=n,s.height=o,s.style.position="absolute",s.style.left="0",s.style.bottom="0",e=s.getContext("2d");var t;for(var i=0;i<n*r.density;i++){var h=new p;a.push(h)}d()}(),window.addEventListener("resize",c,!1)}}(jQuery),"object"==typeof window&&(window.Ribbons=function(){var t=window,i=document.body,n=document.documentElement,o=function(){if(1===arguments.length){if(Array.isArray(arguments[0])){var t=Math.round(o(0,arguments[0].length-1));return arguments[0][t]}return o(0,arguments[0])}return 2===arguments.length?Math.random()*(arguments[1]-arguments[0])+arguments[0]:0},s=function(o){var s=Math.max(0,t.innerWidth||n.clientWidth||i.clientWidth||0),e=Math.max(0,t.innerHeight||n.clientHeight||i.clientHeight||0);return{width:s,height:e,ratio:s/e,centerx:s/2,centery:e/2,scrollx:Math.max(0,t.pageXOffset||n.scrollLeft||i.scrollLeft||0)-(n.clientLeft||0),scrolly:Math.max(0,t.pageYOffset||n.scrollTop||i.scrollTop||0)-(n.clientTop||0)}},e=function(t,i){this.x=0,this.y=0,this.set(t,i)};e.prototype={constructor:e,set:function(t,i){this.x=t||0,this.y=i||0},copy:function(t){return this.x=t.x||0,this.y=t.y||0,this},multiply:function(t,i){return this.x*=t||1,this.y*=i||1,this},divide:function(t,i){return this.x/=t||1,this.y/=i||1,this},add:function(t,i){return this.x+=t||0,this.y+=i||0,this},subtract:function(t,i){return this.x-=t||0,this.y-=i||0,this},clampX:function(t,i){return this.x=Math.max(t,Math.min(this.x,i)),this},clampY:function(t,i){return this.y=Math.max(t,Math.min(this.y,i)),this},flipX:function(){return this.x*=-1,this},flipY:function(){return this.y*=-1,this}};var h=function(t){this._canvas=null,this._context=null,this._sto=null,this._width=0,this._height=0,this._scroll=0,this._ribbons=[],this._options={colorSaturation:"80%",colorBrightness:"60%",colorAlpha:.65,colorCycleSpeed:6,verticalPosition:"center",horizontalSpeed:150,ribbonCount:3,strokeSize:0,parallaxAmount:-.5,animateSections:!0},this._onDraw=this._onDraw.bind(this),this._onResize=this._onResize.bind(this),this._onScroll=this._onScroll.bind(this),this.setOptions(t),this.init()};return h.prototype={constructor:h,setOptions:function(t){if("object"==typeof t)for(var i in t)t.hasOwnProperty(i)&&(this._options[i]=t[i])},init:function(){try{this._canvas=document.createElement("canvas"),this._canvas.style.display="block",this._canvas.style.position="fixed",this._canvas.style.margin="0",this._canvas.style.padding="0",this._canvas.style.border="0",this._canvas.style.outline="0",this._canvas.style.left="0",this._canvas.style.top="0",this._canvas.style.width="100%",this._canvas.style.height="100%",this._canvas.style["z-index"]="-1",this._onResize(),this._context=this._canvas.getContext("2d"),this._context.clearRect(0,0,this._width,this._height),this._context.globalAlpha=this._options.colorAlpha,window.addEventListener("resize",this._onResize),document.body.appendChild(this._canvas)}catch(t){return void console.warn("Canvas Context Error: "+t.toString())}this._onDraw()},addRibbon:function(){var t=Math.round(o(1,9))>5