skrollr.menu.min.js 1.5 KB

12
  1. /*! skrollr-menu 0.1.12 (2014-05-10) | Alexander Prinzhorn - https://github.com/Prinzhorn/skrollr-menu | Free to use under terms of MIT license */
  2. (function(t,e){"use strict";var n=500,o="sqrt",r=1,i="data-menu-top",u="data-menu-offset",a=e.skrollr,c=e.history,l=!!c.pushState,s=function(e){return e===t?!1:"A"===e.tagName.toUpperCase()?e:s(e.parentNode)},f=function(t){if(1===t.which||0===t.button){var e=s(t.target);e&&p(e)&&t.preventDefault()}},p=function(e,n){var o=e.getAttribute("href");if(!/^#/.test(o))return!1;var r,a;if(a=S?S(e):e.getAttribute(i),null!==a)r=/p$/.test(a)?a.slice(0,-1)/100*t.documentElement.clientHeight:+a*T;else{var s=t.getElementById(o.substr(1));if(!s)return!1;r=m.relativeToAbsolute(s,"top","top");var f=s.getAttribute(u);null!==f&&(r+=+f)}return l&&!n&&c.pushState({top:r},"",o),b&&!n?m.animateTo(r,{duration:g(m.getScrollTop(),r),easing:v}):d(function(){m.setScrollTop(r)}),!0},h=function(){if(e.location.hash&&t.querySelector){var n=t.querySelector('a[href="'+e.location.hash+'"]');n&&p(n,!0)}},d=function(t){e.setTimeout(t,1)};a.menu={},a.menu.init=function(i,u){m=i,u=u||{},v=u.easing||o,b=u.animate!==!1,g=u.duration||n,S=u.handleLink,T=u.scale||r,"number"==typeof g&&(g=function(t){return function(){return t}}(g)),a.addEvent(t,"click",f),l&&a.addEvent(e,"popstate",function(t){var e=t.state||{},n=e.top||0;d(function(){m.setScrollTop(n)})},!1),h()},a.menu.click=function(t){p(t)};var m,v,g,b,S,T;d(function(){e.location.hash&&e.scrollTo(0,0)})})(document,window);