26 Star 70 Fork 19

小为 / placeholder.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
placeholder.min.js 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
hustcc 提交于 2016-04-21 18:42 . v3.0.0, module supported
/*!
placeholder.js - client side image placeholders
© 2015 Hustcc - http://placeholder.cn/
Issues: https://github.com/hustcc/placeholder.js/issues
License: MIT
*/
;!function(a,b){if(typeof module==="object"&&module.exports){module.exports=b(a)}else{a.placeholder=b(a)}}(typeof window!=="undefined"?window:this,function(j){var k,e,n=j.requestAnimationFrame||j.webkitRequestAnimationFrame||j.mozRequestAnimationFrame||j.oRequestAnimationFrame||j.msRequestAnimationFrame||function(c){j.setTimeout(c,1000/60)},a="placeholder-rendered";function i(t){if(!k||!e){k=document.createElement("canvas");e=k.getContext("2d")}var r=parseInt(t.a[0]),q=parseInt(t.a[1]);k.width=r;k.height=q;e.clearRect(0,0,r,q);e.fillStyle=t.c;e.fillRect(0,0,r,q);e.fillStyle=t.d;e.font=t.e+" normal "+t.f+" "+(t.g||100)+"px "+t.h;var u=1;if(t.g===""){var c=0.7*r,p=0.7*q,o=e.measureText(t.b).width,s=100;u=Math.min(c/o,p/s)}e.translate(r/2,q/2);e.scale(u,u);e.textAlign="center";e.textBaseline="middle";e.fillText(t.b,0,0);return k}function h(){return"#"+("00000"+(Math.random()*16777216<<0).toString(16)).slice(-6)}function f(c){c=c||{};var v=c.size||"128x128",u=c.text||v,w=c.bgcolor||h(),q=c.color||h(),r=c.fstyle||"normal",t=c.fweight||"bold",o=c.fsize||"",s=c.ffamily||"consolas",p={};v=v.split("x");if(v.length!==2){v=[128,128]}p.a=v;p.b=u;p.c=w;p.d=q;p.e=r;p.f=t;p.g=o;p.h=s;c=null;return p}function g(c){c=f(c);return i(c)}function m(c){return g(c).toDataURL()}function l(p,o,c){return p.getAttribute(o)||c}function d(c){var r={},q=c.split("&"),p;for(var o in q){p=q[o].split("=");try{r[p[0]]=decodeURIComponent(p[1])}catch(s){r[p[0]]=p[1]}}return r}function b(){var c=document.querySelectorAll("img.placeholder"),o,q;for(var p=0;p<c.length;p++){o=c[p];if(!l(o,a,"")){q=d(l(o,"options",""));o.setAttribute("src",m(q));o.setAttribute(a,"1")}}n(b)}b();return{getData:m,getCanvas:g}});
JavaScript
1
https://gitee.com/hustcc/placeholder.js.git
git@gitee.com:hustcc/placeholder.js.git
hustcc
placeholder.js
placeholder.js
master

搜索帮助