1 Star 0 Fork 19

beargolden/placeholder.js

forked from 小为/placeholder.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
placeholder.min.js 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
hustcc 提交于 2015-12-25 13:14 . fix #3
(function(){var j,e,m=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(c){window.setTimeout(c,1000/60)},a="placeholder-rendered";function i(s){if(!j||!e){j=document.createElement("canvas");e=j.getContext("2d")}var q=parseInt(s.a[0]),p=parseInt(s.a[1]);j.width=q;j.height=p;e.clearRect(0,0,q,p);e.fillStyle=s.c;e.fillRect(0,0,q,p);e.fillStyle=s.d;e.font=s.e+" normal "+s.f+" "+(s.g||100)+"px "+s.h;var t=1;if(s.g===""){var c=0.7*q,o=0.7*p,n=e.measureText(s.b).width,r=100;t=Math.min(c/n,o/r)}e.translate(q/2,p/2);e.scale(t,t);e.textAlign="center";e.textBaseline="middle";e.fillText(s.b,0,0);return j}function g(){return"#"+("00000"+(Math.random()*16777216<<0).toString(16)).slice(-6)}function f(c){c=c||{};var u=c.size||"128x128",t=c.text||u,v=c.bgcolor||g(),p=c.color||g(),q=c.fstyle||"normal",s=c.fweight||"bold",n=c.fsize||"",r=c.ffamily||"consolas",o={};u=u.split("x");if(u.length!==2){u=[128,128]}o.a=u;o.b=t;o.c=v;o.d=p;o.e=q;o.f=s;o.g=n;o.h=r;c=null;return o}function h(c){c=f(c);return i(c)}function l(c){return h(c).toDataURL()}function k(o,n,c){return o.getAttribute(n)||c}function d(c){var q={},p=c.split("&"),o;for(var n in p){o=p[n].split("=");try{q[o[0]]=decodeURIComponent(o[1])}catch(r){q[o[0]]=o[1]}}return q}function b(){var c=document.querySelectorAll("img.placeholder"),n,p;for(var o=0;o<c.length;o++){n=c[o];if(!k(n,a,"")){p=d(k(n,"options",""));n.setAttribute("src",l(p));n.setAttribute(a,"1")}}m(b)}b();window.placeholder={getData:l,getCanvas:h}})();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/beargolden/placeholder.js.git
git@gitee.com:beargolden/placeholder.js.git
beargolden
placeholder.js
placeholder.js
master

搜索帮助