-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamicImage.min.js
1 lines (1 loc) · 1.56 KB
/
dynamicImage.min.js
1
function DynamicImage(t){function n(t){return function(){return t}}function e(t,n){function e(){i=!1,t()}var i=!1;return function(){i||(i=!0,l.setTimeout(e,n))}}function i(t,n,e){t[n]!=e&&(t[n]=e)}function f(t){for(var n=t.offsetTop,e=t.offsetLeft,i=t.offsetWidth,f=t.offsetHeight,r=l.pageXOffset,o=l.pageYOffset;t.offsetParent;)t=t.offsetParent,n+=t.offsetTop,e+=t.offsetLeft;return n<o+l.innerHeight&&e<r+l.innerWidth&&n+f>o&&e+i>r}function r(t,e,i,f){function r(){i(),f()&&t.removeEventListener(e,r)}f=f||n(!1),this.register=function(){t.addEventListener(e,r)}}function o(){i(d.style,"height",w())}function u(){if(o(),f(d)){var t=d.offsetWidth;if(!(A>=t)){for(var n=m[0],e=1;e<m.length&&m[e-1].width<t;++e)n=m[e];n.width>A&&(d.src=n.src,A=n.width,o())}}}function c(){if(0===m.length)return!1;var t=m[m.length-1].width;return A==t}function s(){return-1!=A}function h(t){return function(n){return t(n),g}}function a(){A=-1,d.src="data:image/gif;base64,R0lGODlhAQABAIABAKCgoP///yH5BAEKAAEALAAAAAABAAEAAAICRAEAOw==",u(),p.register(),E.register(),d.onload=u}t=t||500;var d=document.createElement("img"),A=-1,g=this,l=window,w=n("100%"),m=[],v=e(u,t),p=new r(l,"scroll",v,s),E=new r(l,"resize",v,c);a(),g.appendTo=h(function(t){var n=document.getElementById(t);n&&n.appendChild(d)}),g.width=h(function(t){i(d.style,"width",t)}),g.height=h(function(t){w=n(t)}),g.heightAsPixelRatioOfWidth=h(function(t){w=function(){var n=Math.round(d.offsetWidth*t);return n+"px"}}),g.update=h(u),g.sources=h(function(t){m=t,a()}),g.singleSource=h(function(t){m=[{width:1e5,src:t}],a()}),g.getElement=function(){return d}}