You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

2 lines
7.9 KiB

/*! skrollr v0.5.11 https://github.com/Prinzhorn/skrollr | free to use under terms of MIT license */
(function(e,t,n){"use strict";function j(n){s=t.documentElement,o=t.body,H(),et=this,n=n||{},ut=n.constants||{};if(n.easing)for(var i in n.easing)B[i]=n.easing[i];nt={beforerender:n.beforerender,render:n.render},rt=n.forceHeight!==!1,ht=n.smoothScrolling!==!1,pt={targetTop:et.getScrollTop()},rt&&(ot=n.scale||1),K(s,[l],[c]);if(rt){var u=t.getElementById("skrollr-body")||t.createElement("div"),a=u.style;a.minWidth="1px",a.position="absolute",a.top=a.zIndex="0",u.id||(a.width="1px",a.right="0",o.appendChild(u)),st=function(){it=0,F(),a.height=it+s.clientHeight+"px",dt=!0,r.iscroll&&e.setTimeout(function(){r.iscroll.refresh()},0)}}else st=function(){it=o.scrollHeight-s.clientHeight,F(),dt=!0,r.iscroll&&e.setTimeout(function(){r.iscroll.refresh()},0)};return et.refresh(),$("resize",st),function f(){S(f),q()}(),et}var r=e.skrollr={get:function(){return et},init:function(e){return et||new j(e)},VERSION:"0.5.11"},i=Object.prototype.hasOwnProperty,s,o,u="rendered",a="un"+u,f="skrollable",l="skrollr",c="no-"+l,h="linear",p=1e3,d=200,v="start",m="end",g="top",y="center",b="bottom",w="___has_rendered_class",E="___skrollable_id",S=e.requestAnimationFrame;(function(){var t=["ms","moz","webkit","o"],n;for(n=0;n<t.length&&!S;n++)S=e[t[n]+"RequestAnimationFrame"];var r=0;S||(S=function(t){var n=Y(),i=Math.max(0,30-(n-r));e.setTimeout(function(){t(n+i)},i),r=n+i})})();var x=/^\s*(.+)\s*$/m,T=/^data(?:-(_\w+))?(?:-?(-?\d+))?(?:-?(start|end|top|center|bottom))?(?:-?(top|center|bottom))?$/,N=/\s*([a-z\-\[\]]+)\s*:\s*(.+?)\s*(?:;|$)/gi,C=/^([a-z\-]+)\[(\w+)\]$/,k=/-([a-z])/g,L=function(e,t){return t.toUpperCase()},A=/[\-+]?[\d]*\.?[\d]+/g,O=/\{\?\}/g,M=/rgba?\(\s*-?\d+\s*,\s*-?\d+\s*,\s*-?\d+/g,_=/[a-z\-]+-gradient/g,D,P,H=function(){var t=/^(?:O|Moz|webkit|ms)/;if(e.getComputedStyle){var n=e.getComputedStyle(o,null);for(var r in n){D=r.match(t)||+r==r&&n[r].match(t);if(D)break}}D=(D||[""])[0],P="-"+D.toLowerCase()+"-"},B={begin:function(){return 0},end:function(){return 1},linear:function(e){return e},quadratic:function(e){return e*e},cubic:function(e){return e*e*e},swing:function(e){return-Math.cos(e*Math.PI)/2+.5},sqrt:function(e){return Math.sqrt(e)},bounce:function(e){var t;if(e<=.5083)t=3;else if(e<=.8489)t=9;else if(e<=.96208)t=27;else{if(!(e<=.99981))return 1;t=91}return 1-Math.abs(3*Math.cos(e*t*1.028)/t)}};j.prototype.refresh=function(e){var r,i=!1;e===n?(i=!0,tt=[],vt=0,e=t.getElementsByTagName("*")):e=[].concat(e);for(r=0;r<e.length;r++){var s=e[r],o=s,l=[],c=ht;if(!s.attributes)continue;for(var h=0;h<s.attributes.length;h++){var p=s.attributes[h];if(p.name==="data-anchor-target"){o=t.querySelector(p.value);if(o===null)throw'Unable to find anchor target "'+p.value+'"';continue}if(p.name==="data-smooth-scrolling"){c=p.value!=="off";continue}var d=p.name.match(T);if(d!==null){var g=d[1];g=g&&ut[g.substr(1)]||0;var y=(d[2]|0)+g,b=d[3],S=d[4]||b,x={offset:y,props:p.value,element:s};l.push(x),!b||b===v||b===m?(x.mode="absolute",b===m?x.isEnd=!0:(x.frame=y*ot,delete x.offset)):(x.mode="relative",x.anchors=[b,S])}}if(l.length){var N,C,k;!i&&E in s?(k=s[E],N=tt[k].styleAttr,C=tt[k].classAttr):(k=s[E]=vt++,N=s.style.cssText,C=J(s));var L=tt[k]={element:s,styleAttr:N,classAttr:C,anchorTarget:o,keyFrames:l,smoothScrolling:c};K(s,[f,u],[a]),L[w]=!0}}st();for(r=0;r<e.length;r++){var A=tt[e[r][E]];if(A===n)continue;A.keyFrames.sort(Z),R(A),z(A)}return et},j.prototype.relativeToAbsolute=function(e,t,n){var r=s.clientHeight,i=e.getBoundingClientRect(),o=i.top,u=i.bottom-i.top;return t===b?o-=r:t===y&&(o-=r/2),n===b?o+=u:n===y&&(o+=u/2),o+=et.getScrollTop(),o+.5|0},j.prototype.animateTo=function(e,t){t=t||{};var r=Y(),i=et.getScrollTop();return ct={startTop:i,topDiff:e-i,targetTop:e,duration:t.duration||p,startTime:r,endTime:r+(t.duration||p),easing:B[t.easing||h],done:t.done},ct.topDiff||(ct.done&&ct.done.call(et,!1),ct=n),et},j.prototype.stopAnimateTo=function(){ct&&ct.done&&ct.done.call(et,!0),ct=n},j.prototype.isAnimatingTo=function(){return!!ct},j.prototype.setScrollTop=function(t){return r.iscroll?r.iscroll.scrollTo(0,-t):e.scrollTo(0,t),et},j.prototype.getScrollTop=function(){return r.iscroll?-r.iscroll.y:e.pageYOffset||s.scrollTop||o.scrollTop||0},j.prototype.on=function(e,t){return nt[e]=t,et},j.prototype.off=function(e){return delete nt[e],et};var F=function(){var e,t,n,r,i,s,o,u,a;for(s=0;s<tt.length;s++){e=tt[s],t=e.element,n=e.anchorTarget,r=e.keyFrames;for(o=0;o<r.length;o++)i=r[o],i.mode==="relative"&&(u=t.style.cssText,a=J(t),t.style.cssText=e.styleAttr,K(t,e.classAttr),i.frame=et.relativeToAbsolute(n,i.anchors[0],i.anchors[1])-i.offset,t.style.cssText=u,K(t,a)),rt&&!i.isEnd&&i.frame>it&&(it=i.frame)}for(s=0;s<tt.length;s++){e=tt[s],r=e.keyFrames;for(o=0;o<r.length;o++)i=r[o],i.isEnd&&(i.frame=it-i.offset)}},I=function(e,t){for(var n=0;n<tt.length;n++){var s=tt[n],o=s.smoothScrolling?e:t,f=s.keyFrames,l=f[0].frame,c=f[f.length-1].frame,h=o<=l,p=o>=c,d,v;if(h||p){var m=f[h?0:f.length-1].props;for(d in m)i.call(m,d)&&(v=V(m[d].value),r.setStyle(s.element,d,v));s[w]&&(o<l||o>c)&&(K(s.element,[a],[u]),s[w]=!1);continue}s[w]||(K(s.element,[u],[a]),s[w]=!0);for(var g=0;g<f.length-1;g++)if(o>=f[g].frame&&o<=f[g+1].frame){var y=f[g],b=f[g+1];for(d in y.props)if(i.call(y.props,d)){var E=(o-y.frame)/(b.frame-y.frame);E=y.props[d].easing(E),v=X(y.props[d].value,b.props[d].value,E),v=V(v),r.setStyle(s.element,d,v)}break}}},q=function(){var e=et.getScrollTop(),t,r=Y(),i;if(ct)r>=ct.endTime?(e=ct.targetTop,t=ct.done,ct=n):(i=ct.easing((r-ct.startTime)/ct.duration),e=ct.startTop+i*ct.topDiff|0),et.setScrollTop(e);else{var s=pt.targetTop-e;s&&(pt={startTop:ft,topDiff:e-ft,targetTop:e,startTime:lt,endTime:lt+d}),r<=pt.endTime&&(i=B.sqrt((r-pt.startTime)/d),e=pt.startTop+i*pt.topDiff|0)}e<0&&(e=0);if(dt||ft!==e){at=e>=ft?"down":"up",dt=!1;var o={curTop:e,lastTop:ft,maxTop:it,direction:at},u=nt.beforerender&&nt.beforerender.call(et,o);u!==!1&&(I(e,et.getScrollTop()),ft=e,nt.render&&nt.render.call(et,o)),t&&t.call(et,!1)}lt=r},R=function(e){for(var t=0;t<e.keyFrames.length;t++){var n=e.keyFrames[t],r,i,s,o={},u;while((u=N.exec(n.props))!==null)s=u[1],i=u[2],r=s.match(C),r!==null?(s=r[1],r=r[2]):r=h,i=i.indexOf("!")?U(i):[i.slice(1)],o[s]={value:i,easing:B[r]};n.props=o}},U=function(e){var t=[];return M.lastIndex=0,e=e.replace(M,function(e){return e.replace(A,function(e){return e/255*100+"%"})}),_.lastIndex=0,e=e.replace(_,function(e){return P+e}),e=e.replace(A,function(e){return t.push(+e),"{?}"}),t.unshift(e),t},z=function(e){var t={},n;for(n=0;n<e.keyFrames.length;n++)W(e.keyFrames[n],t);t={};for(n=e.keyFrames.length-1;n>=0;n--)W(e.keyFrames[n],t)},W=function(e,t){var n;for(n in t)i.call(e.props,n)||(e.props[n]=t[n]);for(n in e.props)t[n]=e.props[n]},X=function(e,t,n){if(e.length!==t.length)throw"Can't interpolate between \""+e[0]+'" and "'+t[0]+'"';var r=[e[0]];for(var i=1;i<e.length;i++)r[i]=e[i]+(t[i]-e[i])*n;return r},V=function(e){var t=1;return O.lastIndex=0,e[0].replace(O,function(){return e[t++]})};r.setStyle=function(e,t,n){var r=e.style;t=t.replace(k,L).replace("-","");if(t==="zIndex")r[t]=""+(n|0);else if(t==="float")r.styleFloat=r.cssFloat=n;else try{r[D+t.slice(0,1).toUpperCase()+t.slice(1)]=n,r[t]=n}catch(i){}};var $=function(t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)},J=function(t){var n="className";return e.SVGElement&&t instanceof e.SVGElement&&(t=t[n],n="baseVal"),t[n]},K=function(t,r,i){var s="className";e.SVGElement&&t instanceof e.SVGElement&&(t=t[s],s="baseVal");if(i===n){t[s]=r;return}var o=t[s];for(var u=0;u<r.length;u++)G(o).indexOf(G(r[u]))===-1&&(o+=" "+r[u]);for(var a=0;a<i.length;a++)o=G(o).replace(G(i[a])," ");t[s]=Q(o)},Q=function(e){return e.replace(x,"$1")},G=function(e){return" "+e+" "},Y=Date.now||function(){return+(new Date)},Z=function(e,t){return e.frame-t.frame},et,tt,nt,rt,it=0,st,ot=1,ut,at="down",ft=-1,lt=Y(),ct,ht,pt,dt,vt=0})(window,document);