/* * skrollr core * * Alexander Prinzhorn - https://github.com/Prinzhorn/skrollr * * Free to use under terms of MIT license */ (function(window,document,undefined){var skrollr={get:function(){return _instance},init:function(options){return _instance||new Skrollr(options)},VERSION:"0.6.30"};var hasProp=Object.prototype.hasOwnProperty;var Math=window.Math;var getStyle=window.getComputedStyle;var documentElement;var body;var EVENT_TOUCHSTART="touchstart";var EVENT_TOUCHMOVE="touchmove";var EVENT_TOUCHCANCEL="touchcancel";var EVENT_TOUCHEND="touchend";var SKROLLABLE_CLASS="skrollable";var SKROLLABLE_BEFORE_CLASS=SKROLLABLE_CLASS+"-before";var SKROLLABLE_BETWEEN_CLASS=SKROLLABLE_CLASS+"-between";var SKROLLABLE_AFTER_CLASS=SKROLLABLE_CLASS+"-after";var SKROLLR_CLASS="skrollr";var NO_SKROLLR_CLASS="no-"+SKROLLR_CLASS;var SKROLLR_DESKTOP_CLASS=SKROLLR_CLASS+"-desktop";var SKROLLR_MOBILE_CLASS=SKROLLR_CLASS+"-mobile";var DEFAULT_EASING="linear";var DEFAULT_DURATION=1000;var DEFAULT_MOBILE_DECELERATION=0.004;var DEFAULT_SKROLLRBODY="skrollr-body";var DEFAULT_SMOOTH_SCROLLING_DURATION=200;var ANCHOR_START="start";var ANCHOR_END="end";var ANCHOR_CENTER="center";var ANCHOR_BOTTOM="bottom";var SKROLLABLE_ID_DOM_PROPERTY="___skrollable_id";var rxTouchIgnoreTags=/^(?:input|textarea|button|select)$/i;var rxTrim=/^\s+|\s+$/g;var rxKeyframeAttribute=/^data(?:-(_\w+))?(?:-?(-?\d*\.?\d+p?))?(?:-?(start|end|top|center|bottom))?(?:-?(top|center|bottom))?$/;var rxPropValue=/\s*(@?[\w\-\[\]]+)\s*:\s*(.+?)\s*(?:;|$)/gi;var rxPropEasing=/^(@?[a-z\-]+)\[(\w+)\]$/;var rxCamelCase=/-([a-z0-9_])/g;var rxCamelCaseFn=function(str,letter){return letter.toUpperCase()};var rxNumericValue=/[\-+]?[\d]*\.?[\d]+/g;var rxInterpolateString=/\{\?\}/g;var rxRGBAIntegerColor=/rgba?\(\s*-?\d+\s*,\s*-?\d+\s*,\s*-?\d+/g;var rxGradient=/[a-z\-]+-gradient/g;var theCSSPrefix="";var theDashedCSSPrefix="";var detectCSSPrefix=function(){var rxPrefixes=/^(?:O|Moz|webkit|ms)|(?:-(?:o|moz|webkit|ms)-)/;if(!getStyle){return}var style=getStyle(body,null);for(var k in style){theCSSPrefix=(k.match(rxPrefixes)||(+k==k&&style[k].match(rxPrefixes)));if(theCSSPrefix){break}}if(!theCSSPrefix){theCSSPrefix=theDashedCSSPrefix="";return}theCSSPrefix=theCSSPrefix[0];if(theCSSPrefix.slice(0,1)==="-"){theDashedCSSPrefix=theCSSPrefix;theCSSPrefix=({"-webkit-":"webkit","-moz-":"Moz","-ms-":"ms","-o-":"O"})[theCSSPrefix]}else{theDashedCSSPrefix="-"+theCSSPrefix.toLowerCase()+"-"}};var polyfillRAF=function(){var requestAnimFrame=window.requestAnimationFrame||window[theCSSPrefix.toLowerCase()+"RequestAnimationFrame"];var lastTime=_now();if(_isMobile||!requestAnimFrame){requestAnimFrame=function(callback){var deltaTime=_now()-lastTime;var delay=Math.max(0,1000/60-deltaTime);return window.setTimeout(function(){lastTime=_now();callback()},delay)}}return requestAnimFrame};var polyfillCAF=function(){var cancelAnimFrame=window.cancelAnimationFrame||window[theCSSPrefix.toLowerCase()+"CancelAnimationFrame"];if(_isMobile||!cancelAnimFrame){cancelAnimFrame=function(timeout){return window.clearTimeout(timeout)}}return cancelAnimFrame};var easings={begin:function(){return 0},end:function(){return 1},linear:function(p){return p},quadratic:function(p){return p*p},cubic:function(p){return p*p*p},swing:function(p){return(-Math.cos(p*Math.PI)/2)+0.5},sqrt:function(p){return Math.sqrt(p)},outCubic:function(p){return(Math.pow((p-1),3)+1)},bounce:function(p){var a;if(p<=0.5083){a=3}else{if(p<=0.8489){a=9}else{if(p<=0.96208){a=27}else{if(p<=0.99981){a=91}else{return 1}}}}return 1-Math.abs(3*Math.cos(p*a*1.028)/a)}};function Skrollr(options){documentElement=document.documentElement;body=document.body;detectCSSPrefix();_instance=this;options=options||{};_constants=options.constants||{};if(options.easing){for(var e in options.easing){easings[e]=options.easing[e]}}_edgeStrategy=options.edgeStrategy||"set";_listeners={beforerender:options.beforerender,render:options.render,keyframe:options.keyframe};_forceHeight=options.forceHeight!==false;if(_forceHeight){_scale=options.scale||1}_mobileDeceleration=options.mobileDeceleration||DEFAULT_MOBILE_DECELERATION;_smoothScrollingEnabled=options.smoothScrolling!==false;_smoothScrollingDuration=options.smoothScrollingDuration||DEFAULT_SMOOTH_SCROLLING_DURATION;_smoothScrolling={targetTop:_instance.getScrollTop()};_isMobile=((options.mobileCheck||function(){return(/Android|iPhone|iPad|iPod|BlackBerry/i).test(navigator.userAgent||navigator.vendor||window.opera)})());if(_isMobile){_skrollrBody=document.getElementById(options.skrollrBody||DEFAULT_SKROLLRBODY);if(_skrollrBody){_detect3DTransforms()}_initMobile();_updateClass(documentElement,[SKROLLR_CLASS,SKROLLR_MOBILE_CLASS],[NO_SKROLLR_CLASS])}else{_updateClass(documentElement,[SKROLLR_CLASS,SKROLLR_DESKTOP_CLASS],[NO_SKROLLR_CLASS])}_instance.refresh();_addEvent(window,"resize orientationchange",function(){var width=documentElement.clientWidth;var height=documentElement.clientHeight;if(height!==_lastViewportHeight||width!==_lastViewportWidth){_lastViewportHeight=height;_lastViewportWidth=width;_requestReflow=true}});var requestAnimFrame=polyfillRAF();(function animloop(){_render();_animFrame=requestAnimFrame(animloop)}());return _instance}Skrollr.prototype.refresh=function(elements){var elementIndex;var elementsLength;var ignoreID=false;if(elements===undefined){ignoreID=true;_skrollables=[];_skrollableIdCounter=0;elements=document.getElementsByTagName("*")}else{if(elements.length===undefined){elements=[elements]}}elementIndex=0;elementsLength=elements.length;for(;elementIndex_maxKeyFrame){targetRatio=(_maxKeyFrame-targetTop)/targetOffset;targetTop=_maxKeyFrame}else{if(targetTop<0){targetRatio=-targetTop/targetOffset;targetTop=0}}duration=duration*(1-targetRatio);_instance.animateTo((targetTop+0.5)|0,{easing:"outCubic",duration:duration});break}});window.scrollTo(0,0);documentElement.style.overflow=body.style.overflow="hidden"};var _updateDependentKeyFrames=function(){var viewportHeight=documentElement.clientHeight;var processedConstants=_processConstants();var skrollable;var element;var anchorTarget;var keyFrames;var keyFrameIndex;var keyFramesLength;var kf;var skrollableIndex;var skrollablesLength;var offset;var constantValue;skrollableIndex=0;skrollablesLength=_skrollables.length;for(;skrollableIndex_maxKeyFrame){_maxKeyFrame=kf.frame}}}}_maxKeyFrame=Math.max(_maxKeyFrame,_getDocumentHeight());skrollableIndex=0;skrollablesLength=_skrollables.length;for(;skrollableIndexlastFrame.frame;var firstOrLastFrame=beforeFirst?firstFrame:lastFrame;var emitEvents=skrollable.emitEvents;var lastFrameIndex=skrollable.lastFrameIndex;var key;var value;if(beforeFirst||afterLast){if(beforeFirst&&skrollable.edge===-1||afterLast&&skrollable.edge===1){continue}if(beforeFirst){_updateClass(element,[SKROLLABLE_BEFORE_CLASS],[SKROLLABLE_AFTER_CLASS,SKROLLABLE_BETWEEN_CLASS]);if(emitEvents&&lastFrameIndex>-1){_emitEvent(element,firstFrame.eventType,_direction);skrollable.lastFrameIndex=-1}}else{_updateClass(element,[SKROLLABLE_AFTER_CLASS],[SKROLLABLE_BEFORE_CLASS,SKROLLABLE_BETWEEN_CLASS]);if(emitEvents&&lastFrameIndex=frames[keyFrameIndex].frame&&frame<=frames[keyFrameIndex+1].frame){var left=frames[keyFrameIndex];var right=frames[keyFrameIndex+1];for(key in left.props){if(hasProp.call(left.props,key)){var progress=(frame-left.frame)/(right.frame-left.frame);progress=left.props[key].easing(progress);value=_calcInterpolation(left.props[key].value,right.props[key].value,progress);value=_interpolateString(value);if(key.indexOf("@")===0){element.setAttribute(key.substr(1),value)}else{skrollr.setStyle(element,key,value)}}}if(emitEvents){if(lastFrameIndex!==keyFrameIndex){if(_direction==="down"){_emitEvent(element,left.eventType,_direction)}else{_emitEvent(element,right.eventType,_direction)}skrollable.lastFrameIndex=keyFrameIndex}}break}}}};var _render=function(){if(_requestReflow){_requestReflow=false;_reflow()}var renderTop=_instance.getScrollTop();var afterAnimationCallback;var now=_now();var progress;if(_scrollAnimation){if(now>=_scrollAnimation.endTime){renderTop=_scrollAnimation.targetTop;afterAnimationCallback=_scrollAnimation.done;_scrollAnimation=undefined}else{progress=_scrollAnimation.easing((now-_scrollAnimation.startTime)/_scrollAnimation.duration);renderTop=(_scrollAnimation.startTop+progress*_scrollAnimation.topDiff)|0}_instance.setScrollTop(renderTop,true)}else{if(!_forceRender){var smoothScrollingDiff=_smoothScrolling.targetTop-renderTop;if(smoothScrollingDiff){_smoothScrolling={startTop:_lastTop,topDiff:renderTop-_lastTop,targetTop:renderTop,startTime:_lastRenderCall,endTime:_lastRenderCall+_smoothScrollingDuration}}if(now<=_smoothScrolling.endTime){progress=easings.sqrt((now-_smoothScrolling.startTime)/_smoothScrollingDuration);renderTop=(_smoothScrolling.startTop+progress*_smoothScrolling.topDiff)|0}}}if(_forceRender||_lastTop!==renderTop){_direction=(renderTop>_lastTop)?"down":(renderTop<_lastTop?"up":_direction);_forceRender=false;var listenerParams={curTop:renderTop,lastTop:_lastTop,maxTop:_maxKeyFrame,direction:_direction};var continueRendering=_listeners.beforerender&&_listeners.beforerender.call(_instance,listenerParams);if(continueRendering!==false){_calcSteps(renderTop,_instance.getScrollTop());if(_isMobile&&_skrollrBody){skrollr.setStyle(_skrollrBody,"transform","translate(0, "+-(_mobileOffset)+"px) "+_translateZ)}_lastTop=renderTop;if(_listeners.render){_listeners.render.call(_instance,listenerParams)}}if(afterAnimationCallback){afterAnimationCallback.call(_instance,false)}}_lastRenderCall=now};var _parseProps=function(skrollable){var keyFrameIndex=0;var keyFramesLength=skrollable.keyFrames.length;for(;keyFrameIndex=0;keyFrameIndex--){_fillPropForFrame(sk.keyFrames[keyFrameIndex],propList)}};var _fillPropForFrame=function(frame,propList){var key;for(key in propList){if(!hasProp.call(frame.props,key)){frame.props[key]=propList[key]}}for(key in frame.props){propList[key]=frame.props[key]}};var _calcInterpolation=function(val1,val2,progress){var valueIndex;var val1Length=val1.length;if(val1Length!==val2.length){throw"Can't interpolate between \""+val1[0]+'" and "'+val2[0]+'"'}var interpolated=[val1[0]];valueIndex=1;for(;valueIndex