jquery.multiscroll.min.js 10 KB

12345678
  1. /*
  2. * multiscroll.js 0.2.2
  3. * https://github.com/alvarotrigo/multiscroll.js
  4. * @license MIT licensed
  5. *
  6. * Copyright (C) 2016 alvarotrigo.com - A project by Alvaro Trigo
  7. */
  8. !function(b,e,a,c,d){b.fn.multiscroll=function(O){var ac=b.fn.multiscroll;O=b.extend({verticalCentered:!0,scrollingSpeed:700,easing:"easeInQuart",menu:!1,sectionsColor:[],anchors:[],navigation:!1,navigationPosition:"right",navigationColor:"#000",navigationTooltips:[],loopBottom:!1,loopTop:!1,css3:!1,paddingTop:0,paddingBottom:0,fixedElements:null,normalScrollElements:null,keyboardScrolling:!0,touchSensitivity:5,sectionSelector:".ms-section",leftSelector:".ms-left",rightSelector:".ms-right",afterLoad:null,onLeave:null,afterRender:null,afterResize:null},O);var U=600,ab=navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/),V="ontouchstart" in e||0<navigator.msMaxTouchPoints||navigator.maxTouchPoints;".ms-right"!==O.rightSelector&&b(O.rightSelector).addClass("ms-right"),".ms-left"!==O.leftSelector&&b(O.leftSelector).addClass("ms-left");var ag,j,X,ak=b(".ms-left").find(".ms-section").length,ad=!1,af=b(e).height(),K=function(){var f;f=e.PointerEvent?{down:"pointerdown",move:"pointermove"}:{down:"MSPointerDown",move:"MSPointerMove"};return f}(),ai={touchmove:"ontouchmove" in e?"touchmove":K.move,touchstart:"ontouchstart" in e?"touchstart":K.down};function G(){var f=e.location.hash.replace("#","");if(f.length){var g=b(".ms-left").find('[data-anchor="'+f+'"]');("undefined"==typeof lastScrolledDestiny||f!==lastScrolledDestiny)&&ao(g)}}function Z(f){f.preventDefault();var g=b(this).parent().index();ao(b(".ms-left .ms-section").eq(g))}function I(){var f=b(this).data("tooltip");b('<div class="multiscroll-tooltip '+O.navigationPosition+'">'+f+"</div>").hide().appendTo(b(this)).fadeIn(200)}function al(){b(this).find(".multiscroll-tooltip").fadeOut(200,function(){b(this).remove()})}am(),ap(),O.css3&&(O.css3=function(){var f,i=a.createElement("p"),g={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};for(var h in a.body.insertBefore(i,null),g){i.style[h]!==d&&(i.style[h]="translate3d(1px,1px,1px)",f=e.getComputedStyle(i).getPropertyValue(g[h]))}return a.body.removeChild(i),f!==d&&0<f.length&&"none"!==f}()),b("html, body").css({overflow:"hidden",height:"100%"}),".ms-section"!==O.sectionSelector&&b(O.sectionSelector).each(function(){b(this).addClass("ms-section")}),O.navigation&&(b("body").append('<div id="multiscroll-nav"><ul></ul></div>'),(ag=b("#multiscroll-nav")).css("color",O.navigationColor),ag.addClass(O.navigationPosition)),b(".ms-right, .ms-left").css({width:"50%",position:"absolute",height:"100%","-ms-touch-action":"none"}),b(".ms-right").css({right:"0px",top:"0","-ms-touch-action":"none","touch-action":"none"}),b(".ms-left").css({left:"0",top:"0","-ms-touch-action":"none","touch-action":"none"}),b(".ms-left .ms-section, .ms-right .ms-section").each(function(){var f,i=b(this).index();if((O.paddingTop||O.paddingBottom)&&b(this).css("padding",O.paddingTop+" 0 "+O.paddingBottom+" 0"),void 0!==O.sectionsColor[i]&&b(this).css("background-color",O.sectionsColor[i]),void 0!==O.anchors[i]&&b(this).attr("data-anchor",O.anchors[i]),O.verticalCentered&&(f=b(this)).addClass("ms-table").wrapInner('<div class="ms-tableCell" style="height: '+Y(f)+'px" />'),b(this).closest(".ms-left").length&&O.navigation){var g="";O.anchors.length&&(g=O.anchors[i]);var h=O.navigationTooltips[i];void 0===h&&(h=""),O.navigation&&ag.find("ul").append('<li data-tooltip="'+h+'"><a href="#'+g+'"><span></span></a></li>')}}),b(".ms-right").html(b(".ms-right").find(".ms-section").get().reverse()),b(".ms-left .ms-section, .ms-right .ms-section").each(function(){var f=b(this).index();b(this).css({height:"100%"}),!f&&O.navigation&&ag.find("li").eq(f).find("a").addClass("active")}).promise().done(function(){b(".ms-left .ms-section.active").length||(b(".ms-right").find(".ms-section").last().addClass("active"),b(".ms-left").find(".ms-section").first().addClass("active")),O.navigation&&ag.css("margin-top","-"+ag.height()/2+"px"),b.isFunction(O.afterRender)&&O.afterRender.call(this),q(),N(),b(e).on("load",function(){var f,g;f=e.location.hash.replace("#",""),g=b('.ms-left .ms-section[data-anchor="'+f+'"]'),f.length&&ao(g)})}),b(e).on("hashchange",G),b(a).keydown(function(f){clearTimeout(X);var h=b(a.activeElement);if(!h.is("textarea")&&!h.is("input")&&!h.is("select")&&O.keyboardScrolling){var g=f.which;-1<b.inArray(g,[40,38,32,33,34])&&f.preventDefault(),X=setTimeout(function(){!function(i){var k=i.shiftKey;switch(i.which){case 38:case 33:ac.moveSectionUp();break;case 32:if(k){ac.moveSectionUp();break}case 40:case 34:ac.moveSectionDown();break;case 36:ac.moveTo(1);break;case 35:ac.moveTo(b(".ms-left .ms-section").length);break;default:}}(f)},150)}}),b(a).mousedown(function(f){if(1==f.button){return f.preventDefault(),!1}}),b(a).on("click","#multiscroll-nav a",Z),b(a).on({mouseenter:I,mouseleave:al},"#multiscroll-nav li"),O.normalScrollElements&&(b(a).on("mouseenter",O.normalScrollElements,function(){ac.setMouseWheelScrolling(!1)}),b(a).on("mouseleave",O.normalScrollElements,function(){ac.setMouseWheelScrolling(!0)})),b(e).on("resize",ah);var R=af;function ah(){if(ab){var f=b(a.activeElement);if(!f.is("textarea")&&!f.is("input")&&!f.is("select")){var g=b(e).height();c.abs(g-R)>20*c.max(R,g)/100&&(an(!0),R=g)}}else{clearTimeout(j),j=setTimeout(function(){an(!0)},350)}}function an(f){af=b(e).height(),b(".ms-tableCell").each(function(){b(this).css({height:Y(b(this).parent())})}),O.scrollOverflow&&scrollBarHandler.createScrollBarForAll(),q(),b.isFunction(O.afterResize)&&O.afterResize.call(this)}function q(){O.css3?(aj(b(".ms-left"),"translate3d(0px, -"+b(".ms-left").find(".ms-section.active").position().top+"px, 0px)",!1),aj(b(".ms-right"),"translate3d(0px, -"+b(".ms-right").find(".ms-section.active").position().top+"px, 0px)",!1)):(b(".ms-left").css("top",-b(".ms-left").find(".ms-section.active").position().top),b(".ms-right").css("top",-b(".ms-right").find(".ms-section.active").position().top))}function ao(k){var C=k.index(),x=b(".ms-right").find(".ms-section").eq(ak-1-C),y=k.data("anchor"),p=b(".ms-left .ms-section.active").index()+1,B=function(i){var m=b(".ms-left .ms-section.active").index(),l=i.index();if(l<m){return"up"}return"down"}(k);ad=!0;var f,u,z,g=k.position().top,w=x.position().top;if(x.addClass("active").siblings().removeClass("active"),k.addClass("active").siblings().removeClass("active"),function(i){O.anchors.length&&(location.hash=i);N()}(y),O.css3){b.isFunction(O.onLeave)&&O.onLeave.call(this,p,C+1,B);var h="translate3d(0px, -"+g+"px, 0px)",D="translate3d(0px, -"+w+"px, 0px)";aj(b(".ms-left"),h,!0),aj(b(".ms-right"),D,!0),setTimeout(function(){b.isFunction(O.afterLoad)&&O.afterLoad.call(this,y,C+1),setTimeout(function(){ad=!1},U)},O.scrollingSpeed)}else{b.isFunction(O.onLeave)&&O.onLeave.call(this,p,C+1,B),b(".ms-left").animate({top:-g},O.scrollingSpeed,O.easing,function(){b.isFunction(O.afterLoad)&&O.afterLoad.call(this,y,C+1),setTimeout(function(){ad=!1},U)}),b(".ms-right").animate({top:-w},O.scrollingSpeed,O.easing)}lastScrolledDestiny=y,f=y,O.menu&&(b(O.menu).find(".active").removeClass("active"),b(O.menu).find('[data-menuanchor="'+f+'"]').addClass("active")),u=y,z=C,O.navigation&&(b("#multiscroll-nav").find(".active").removeClass("active"),u?b("#multiscroll-nav").find('a[href="#'+u+'"]').addClass("active"):b("#multiscroll-nav").find("li").eq(z).find("a").addClass("active"))}function am(){a.addEventListener?(a.addEventListener("mousewheel",H,!1),a.addEventListener("wheel",H,!1)):a.attachEvent("onmousewheel",H)}function H(f){f=e.event||f;var g=c.max(-1,c.min(1,f.wheelDelta||-f.deltaY||-f.detail));return ad||(g<0?ac.moveSectionDown():ac.moveSectionUp()),!1}function aj(f,i,g){var h;f.toggleClass("ms-easing",g),f.css({"-webkit-transform":h=i,"-moz-transform":h,"-ms-transform":h,transform:h})}function N(){var f=b(".ms-left .ms-section.active"),l=f.data("anchor"),h=f.index(),k=String(h);O.anchors.length&&(k=l),k=k.replace("/","-").replace("#","");var g=new RegExp("\\b\\s?ms-viewing-[^\\s]+\\b","g");b("body")[0].className=b("body")[0].className.replace(g,""),b("body").addClass("ms-viewing-"+k)}function Y(f){var h=af;if(O.paddingTop||O.paddingBottom){var g=parseInt(f.css("padding-top"))+parseInt(f.css("padding-bottom"));h=af-g}return h}ac.moveSectionUp=function(){var f=b(".ms-left .ms-section.active").prev(".ms-section");!f.length&&O.loopTop&&(f=b(".ms-left .ms-section").last()),f.length&&ao(f)},ac.moveSectionDown=function(){var f=b(".ms-left .ms-section.active").next(".ms-section");!f.length&&O.loopBottom&&(f=b(".ms-left .ms-section").first()),f.length&&ao(f)},ac.moveTo=function(f){ao(isNaN(f)?b('.ms-left [data-anchor="'+f+'"]'):b(".ms-left .ms-section").eq(f-1))},ac.setKeyboardScrolling=function(f){O.keyboardScrolling=f},ac.setMouseWheelScrolling=function(f){f?am():a.addEventListener?(a.removeEventListener("mousewheel",H,!1),a.removeEventListener("wheel",H,!1)):a.detachEvent("onmousewheel",H)},ac.setScrollingSpeed=function(f){O.scrollingSpeed=f};var W=0,A=0;function J(f){if(aa(f)){event.preventDefault();b(".ms-left .ms-section.active");if(!ad){var g=Q(f);A=g.y,g.x,c.abs(W-A)>b(e).height()/100*O.touchSensitivity&&(A<W?ac.moveSectionDown():W<A&&ac.moveSectionUp())}}}function aa(f){return void 0===f.pointerType||"mouse"!=f.pointerType}function ae(f){if(aa(f)){var g=Q(f);W=g.y,g.x}}function ap(){(V||ab)&&(a.removeEventListener(ai.touchstart,ae),a.removeEventListener(ai.touchmove,J,{passive:!1}),a.addEventListener(ai.touchstart,ae),a.addEventListener(ai.touchmove,J,{passive:!1}))}function Q(f){var g=[];return g.y=void 0!==f.pageY&&(f.pageY||f.pageX)?f.pageY:f.touches[0].pageY,g.x=void 0!==f.pageX&&(f.pageY||f.pageX)?f.pageX:f.touches[0].pageX,V&&aa(f)&&void 0!==f.touches&&(g.y=f.touches[0].pageY,g.x=f.touches[0].pageX),g}ac.destroy=function(){ac.setKeyboardScrolling(!1),ac.setMouseWheelScrolling(!1),(V||ab)&&(a.removeEventListener(ai.touchstart,ae),a.removeEventListener(ai.touchmove,J,{passive:!1})),b(e).off("hashchange",G).off("resize",ah),b(a).off("mouseenter","#multiscroll-nav li").off("mouseleave","#multiscroll-nav li").off("click","#multiscroll-nav a")},ac.build=function(){ac.setKeyboardScrolling(!0),ac.setMouseWheelScrolling(!0),ap(),b(e).on("hashchange",G).on("resize",ah),b(a).on("mouseenter","#multiscroll-nav li",I).on("mouseleave","#multiscroll-nav li",al).on("click","#multiscroll-nav a",Z)}}}(jQuery,window,document,Math);