forked from gopatrik/space.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space.min.js
4 lines (4 loc) · 1.76 KB
/
space.min.js
1
2
3
4
(function(){var m=function(){var b,k,f,c=$(window),a=0,g=0,l=function(){if(f){var h=c.scrollTop();h==a&&30<=++g&&(g=0,window.clearInterval(f),f=void 0);a=h;b()}};return Object.freeze({repeatOnScroll:function(a,d){b=a;k=d;window.onscroll=function(){f||(f=window.setInterval(l,k))}},getScrollTop:function(){return a}})};(function(){var b=document.createElement("style");b.type="text/css";b.innerHTML=".space-frame {display: none;position: fixed;width: 100vw;height: 100vh;} .space-frame .space-inner-frame {position: absolute;transform-style: preserve-3d;top: 50%;left: 50%;-webkit-transform: translate(-50%, -50%);-moz-transform: translate(-50%, -50%);-ms-transform: translate(-50%, -50%);-o-transform: translate(-50%, -50%);transform: translate(-50%, -50%);}";
document.getElementsByTagName("head")[0].appendChild(b)})();(function(){var b=$(window),k=b.height();b.height();b.width();var f=m(),c,a=0,g=[{opacity:{from:1,to:0},scale:{from:1,to:1.5}}],l=function(){window.requestAnimationFrame(function(){var d=f.getScrollTop(),e=c[a].distanceTo;d<e?($(".space-frame").hide(),a--,0>a&&(a=0),$(c[a].selector).show()):d>e+c[a].duration&&($(".space-frame").hide(),a++,$(c[a].selector).show());e=f.getScrollTop()-c[a].distanceTo;d=h(g[0],e,"opacity");e=h(g[0],e,"scale");
$(c[a].selector).css({transform:"scale("+e+")",opacity:d})})},h=function(d,e,b){d=d[b];return+(d.from+e/c[a].duration*(d.to-d.from)).toFixed(4)};return Object.freeze({init:function(){var d=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?.3:1,e=0;c=$(".space-frame").map(function(a,b){var c=(b.dataset.duration||1)*d*k,f=e;e+=c;var g="frame-"+a;b.id=g;return{selector:"#"+g,duration:c,distanceTo:f}});$("body").height(e);$(c[a].selector).show();f.repeatOnScroll(l,
1E3/60)}})})().init()}).call(this);