1 Star 0 Fork 13

铅笔灰/Damoo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
damoo.min.js 3.60 KB
一键复制 编辑 原始数据 按行查看 历史
James Liu 提交于 2015-06-01 01:59 . v2.1.6: fix bugs; formalize apis
/*! Damoo v2.1.6 | Copyright (c) 2015 James Liu | Released under the MIT license */
;(function(d){var f=function(a,b,c,e){if(!(this instanceof f))return new f(a,b,c,e);this.canvas=new h(a,b,c,e);this.thread=new g(c)};f.version="v2.1.6";f.dom=d.document;var n=d.requestAnimationFrame||d.mozRequestAnimationFrame||d.webkitRequestAnimationFrame||d.msRequestAnimationFrame||d.oRequestAnimationFrame||function(a){return setTimeout(a,17)},p=d.cancelAnimationFrame||d.mozCancelAnimationFrame||d.webkitCancelAnimationFrame||d.webkitCancelRequestAnimationFrame||d.msCancelAnimationFrame||d.oCancelAnimationFrame||
function(a){clearTimeout(a)};f.prototype.show=function(){this.canvas.parent.appendChild(this.canvas.layer);return this};f.prototype.hide=function(){this.canvas.parent.removeChild(this.canvas.layer);return this};f.prototype.emit=function(a){var b=this.canvas.font,c=f.dom.createElement("canvas"),e=c.getContext("2d");c.width=b.size*a.text.length*1.2;c.height=1.2*b.size;e.font=b.value;e.textAlign="start";e.textBaseline="top";a.shadow&&(e.shadowOffsetX=1,e.shadowOffsetY=1,e.shadowColor="#fff",e.shadowColor=
a.shadow.color);e.fillStyle="#fff";e.fillStyle=a.color;e.fillText(a.text,0,0);if(a.fixed){for(var b=e.getImageData(0,0,c.width,c.height),d=c.height-1,g,h=0,k=b.data;0<=d;d--)for(g=c.width-1;0<=g;g--)0!=k[4*(d*c.width+g)+3]&&g>h&&(h=g+1);c.width=h;e.putImageData(b,0,0)}this.thread.push({canvas:c,fixed:a.fixed,index:this.thread.index,speed:.6*Math.pow(c.width,1/3),offset:{x:this.canvas.width,y:this.canvas.font.size*this.thread.index}});return this};f.prototype.clear=function(){this.thread.empty();return this};
var k,l=function(){this.canvas.clear();for(var a=0;a<this.thread.length;a++){var b=this.thread.get(a),c=b.offset.x;this.canvas.draw(b,c,b.offset.y);b.offset.x-=b.speed;c<=-b.canvas.width&&this.thread.remove(a)}k=n(function(a){return function(){l.call(a)}}(this))};f.prototype.start=function(){void 0===this.state&&this.clear().show();this.state||(l.call(this),this.state=1);return this};f.prototype.suspend=function(){if(void 0===this.state)return this;p(k);this.state=0;return this};f.prototype.resume=
function(){return this.start()};var h=function(a,b,c,d){this.parent=f.dom.getElementById(a);this.parent.style.position="relative";this.id=b;this.rows=c;this.width=this.parent.offsetWidth;this.height=this.parent.offsetHeight;12>this.height/this.rows&&(this.rows=this.height/12);this.font=new m(this.height/this.rows,d||"sans-serif");this.layer=f.dom.createElement("canvas");this.context=this.layer.getContext("2d");this.layer.id=this.id;this.layer.width=this.width;this.layer.height=this.height;this.layer.style.display=
"block";this.layer.style.backgroundColor="transparent";this.layer.style.position="absolute";this.layer.style.left=0;this.layer.style.top=0;this.layer.style.zIndex=99999};h.prototype.clear=function(){this.context.clearRect(0,0,this.width,this.height)};h.prototype.draw=function(a,b,c){a.fixed?this.context.drawImage(a.canvas,(this.width-a.canvas.width)/2+.5|0,c+.5|0):this.context.drawImage(a.canvas,b+.5|0,c+.5|0)};var m=function(a,b){this.size=a;this.family=b};Object.defineProperty(m.prototype,"value",
{get:function(){return this.size+"px "+this.family}});var g=function(a){this.index=0;this.rows=a;this.pool=[]};g.prototype.push=function(a){this.index++;this.index>=this.rows&&(this.index=0);this.pool.push(a)};g.prototype.get=function(a){return this.pool[a]};g.prototype.remove=function(a){var b=this.get(a).index;this.index>b&&(this.index=b);this.pool.splice(a,1)};g.prototype.empty=function(){this.index=0;this.pool=[]};Object.defineProperty(g.prototype,"length",{get:function(){return this.pool.length}});
d.Damoo=f})(window);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/iso/Damoo.git
git@gitee.com:iso/Damoo.git
iso
Damoo
Damoo
master

搜索帮助