-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrellax.min.js
executable file
·3 lines (3 loc) · 1.46 KB
/
rellax.min.js
1
2
3
var Rellax=function(b,g){var c=Object.create(Rellax.prototype);if("undefined"===typeof window.orientation){var k=0,f=0,d=[];c.options={speed:-4};g&&Object.keys(g).forEach(function(a){c.options[a]=g[a]});-10>c.options.speed?c.options.speed=-10:10<c.options.speed&&(c.options.speed=10);b||(b="rellax");if(document.getElementsByClassName(b.replace(".","")))c.elems=document.getElementsByClassName(b.replace(".",""));else if(!1!==document.querySelector(b))c.elems=querySelector(b);else throw Error("The elements you're trying to select don't exist.");
var n=function(a){var l=0+a.getBoundingClientRect().top,b=a.clientHeight||a.offsetHeight||a.scrollHeight,d=a.dataset.rellaxSpeed?a.dataset.rellaxSpeed:c.options.speed,e=Math.round(100*d*(1-(0-l+f)/(b+f)));a=a.style.cssText.slice(11);return{base:e,top:l,height:b,speed:d,style:a}},m=function(){k=void 0!==window.pageYOffset?window.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop},e=function(){m();for(var a=0;a<c.elems.length;a++){var b="translate3d(0,"+(Math.round(100*
d[a].speed*(1-(k-d[a].top+f)/(d[a].height+f)))-d[a].base)+"px,0)"+d[a].style;c.elems[a].style.cssText="-webkit-transform:"+b+";-moz-transform:"+b+";transform:"+b+";"}},h=0;(function(){f=window.innerHeight;m();for(var a=0;a<c.elems.length;a++){var b=n(c.elems[a]);d.push(b)}window.addEventListener("scroll",function(){e();DEBUG?10>h?h++:(e(),h=0):e()});window.addEventListener("resize",function(){e()});e()})();Object.freeze();return c}};