forked from jamesliu96/damoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
damoo.min.js
6 lines (6 loc) · 2.16 KB
/
damoo.min.js
1
2
3
4
5
6
/*! Damoo v1.1.0 | Copyright (c) 2015 James Liu | Released under the MIT license */
;(function(d){var b=function(a,e,f){if(!(this instanceof b))return new b(a,e,f);this.parent=b.dom.getElementById(a)||b.dom.body;this.canvas=b.dom.createElement("canvas");this.canvas.id=e;this.canvas.width=this.parent.offsetWidth;this.canvas.height=this.parent.offsetHeight;this.canvas.style.display="block";this.canvas.style.backgroundColor="transparent";this.canvas.style.position="relative";this.canvas.style.left=0;this.canvas.style.top=0;this.canvas.style.zIndex=99999;this.rows=f;this.font=new g(this.canvas.height/
this.rows,"Arial");this.thread=new c;this.ctx=this.canvas.getContext("2d");this.ctx.font=this.font.toString();this.ctx.fillStyle="#fff";this.ctx.textAlign="start";this.ctx.textBaseline="bottom"};b.dom=d.document;b.prototype.show=function(){this.parent.appendChild(this.canvas)};b.prototype.hide=function(){this.parent.removeChild(this.canvas)};b.prototype.emit=function(a){this.thread.push({text:a.text,color:a.color,speed:Math.sqrt(a.text.length)/1.5,width:a.text.length*this.font.size,offset:{x:0,y:0}})};
b.prototype.clear=function(){this.thread.empty()};b.prototype.start=function(){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);for(var a=0;a<this.thread.length;a++){var b=this.canvas.width-this.thread.get(a).offset.x,c=this.thread.get(a).offset.y=this.thread.get(a).offset.y||this.font.size*Math.ceil(Math.random()*this.rows);this.ctx.restore();this.ctx.save();this.ctx.fillStyle=this.thread.get(a).color;this.ctx.fillText(this.thread.get(a).text,b,c);this.thread.get(a).offset.x+=this.thread.get(a).speed;
b<=-this.thread.get(a).width&&this.thread.remove(a)}setTimeout(function(a){return function(){a.start()}}(this),1)};var g=function(a,b){this.size=a;this.family=b};g.prototype.toString=function(){return this.size+"px "+this.family};var c=function(){this.memory=[]};c.prototype.push=function(a){this.memory.push(a)};c.prototype.get=function(a){return this.memory[a]};c.prototype.remove=function(a){this.memory.splice(a,1)};c.prototype.empty=function(){this.memory=[]};Object.defineProperty(c.prototype,"length",
{get:function(){return this.memory.length}});d.Damoo=b})(window);