forked from gopatrik/space.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space.min.js
3 lines (3 loc) · 1.26 KB
/
space.min.js
1
2
3
(function(){var m=function(){var f,k,b,c=$(window),a=0,g=0,l=function(){if(b){var h=c.scrollTop();h==a&&30<=++g&&(g=0,window.clearInterval(b),b=void 0);a=h;f()}};return Object.freeze({repeatOnScroll:function(a,d){f=a;k=d;window.onscroll=function(){b||(b=window.setInterval(l,k))}},getScrollTop:function(){return a}})};(function(){var f=$(window),k=f.height();f.height();f.width();var b=m(),c,a=0,g=[{opacity:{from:1,to:0},scale:{from:1,to:1.5}}],l=function(){window.requestAnimationFrame(function(){var d=
b.getScrollTop(),e=c[a].distanceTo;d<e?($(".frame").hide(),a--,0>a&&(a=0),$(c[a].selector).show()):d>e+c[a].duration&&($(".frame").hide(),a++,$(c[a].selector).show());e=b.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=$(".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();b.repeatOnScroll(l,1E3/60)}})})().init()}).call(this);