-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathparaxify.min.js
executable file
·1 lines (1 loc) · 2.22 KB
/
paraxify.min.js
1
!function(e,t,i){"use strict";var o;o=function(i,o){var s,n,r,h,f,g,c;return g=0,c=0,r=0,h={},f=[],n=0,s=function(t,i){this.options={speed:1,boost:0};for(r in i)this.options[r]=i[r];if((this.options.speed<0||this.options.speed>1)&&(this.options.speed=1),t||(t="paraxify"),e.getElementsByClassName(t.replace(".","")))this.photos=e.getElementsByClassName(t.replace(".",""));else{if(e.querySelector(t)===!1)throw new Error("The elements you're trying to select don't exist.");this.photos=querySelector(t)}h=this.options,f=this.photos,this._init(this)},s.prototype={update:function(){for(c=t.innerHeight,r=0;r<f.length;)f[r].style.backgroundPosition="center center",f[r].url=t.getComputedStyle(f[r],!1).backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi,"$2").split(",")[0],f[r].img||(f[r].img=new Image),f[r].url!==f[r].img.src&&(this._check(r),f[r].img.src=f[r].url),r++;this._animate()},_init:function(){this.update(),t.onscroll=function(){this._animate()}.bind(this),t.onresize=function(){this.update()}.bind(this)},_check:function(e){var i,o;o=f[e],o.ok=!0,o.bgSize=t.getComputedStyle(o,!1).backgroundSize,i=c,f[e].img.onload=function(){if(""===o.bgSize||"auto"===o.bgSize){if(this.height<o.offsetHeight)throw o.ok=!1,new Error("The image "+o.url+" ("+this.height+"px) is too short for that container ("+o.offsetHeight+"px).");i=this.height,this.height<c&&(i+=(c-o.offsetHeight)*h.speed)}else if("cover"===o.bgSize){if(c<o.offsetHeight)throw o.ok=!1,new Error("The container ("+o.offsetHeight+"px) can't be bigger than the image ("+c+"px).")}else"cover"===t.getComputedStyle(o,!1).backgroundSize,this._check(e);o.diff=-(i-o.offsetHeight)*h.speed,o.diff=o.diff-o.offsetHeight*h.boost}},_visible:function(e){return g+c>f[e].offsetTop&&g<f[e].offsetTop+f[e].offsetHeight?!0:!1},_animate:function(){var i,o;for(g=void 0!==t.pageYOffset?t.pageYOffset:(e.documentElement||e.body.parentNode||e.body).scrollTop,r=0;r<f.length;)this._check(r),f[r].ok&&"fixed"===t.getComputedStyle(f[r],!1).backgroundAttachment&&this._visible(r)?(i=(g-f[r].offsetTop+c)/(f[r].offsetHeight+c),o=f[r].diff*(i-.5),"cover"!==f[r].bgSize&&(o+=(c-f[r].img.height)/2),o=Math.round(100*o)/100):o="center",f[r].style.backgroundPosition="center "+o+"px",r++}},new s(i,o)},t.paraxify=o}(document,window,0);