forked from alvarotrigo/multiscroll.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.multiscroll.min.js
24 lines (24 loc) · 8.49 KB
/
jquery.multiscroll.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* multiscroll.js 0.1.5 Beta
* https://github.com/alvarotrigo/multiscroll.js
* MIT licensed
*
* Copyright (C) 2013 alvarotrigo.com - A project by Alvaro Trigo
*/
(function(a){a.fn.multiscroll=function(b){function w(){q=a(window).height();a(".ms-tableCell").each(function(){a(this).css({height:r(a(this).parent())})});s();a.isFunction(b.afterResize)&&b.afterResize.call(this)}function s(){b.css3?(m(a(".ms-left"),"translate3d(0px, -"+a(".ms-left").find(".ms-section.active").position().top+"px, 0px)",!1),m(a(".ms-right"),"translate3d(0px, -"+a(".ms-right").find(".ms-section.active").position().top+"px, 0px)",!1)):(a(".ms-left").css("top",-a(".ms-left").find(".ms-section.active").position().top),
a(".ms-right").css("top",-a(".ms-right").find(".ms-section.active").position().top))}function e(c){var d=c.index(),t=a(".ms-right").find(".ms-section").eq(x-1-d),f=c.data("anchor"),e=a(".ms-left .ms-section.active").index()+1,g=y(c);h=!0;b.anchors.length&&(location.hash=f);var k={left:c.position().top,right:t.position().top};t.addClass("active").siblings().removeClass("active");c.addClass("active").siblings().removeClass("active");b.css3?(a.isFunction(b.onLeave)&&b.onLeave.call(this,e,d+1,g),c="translate3d(0px, -"+
k.left+"px, 0px)",k="translate3d(0px, -"+k.right+"px, 0px)",m(a(".ms-left"),c,!0),m(a(".ms-right"),k,!0),setTimeout(function(){a.isFunction(b.afterLoad)&&b.afterLoad.call(this,f,d+1);setTimeout(function(){h=!1},600)},b.scrollingSpeed)):(a.isFunction(b.onLeave)&&b.onLeave.call(this,e,d+1,g),a(".ms-left").animate({top:-k.left},b.scrollingSpeed,b.easing,function(){a.isFunction(b.afterLoad)&&b.afterLoad.call(this,f,d+1);setTimeout(function(){h=!1},600)}),a(".ms-right").animate({top:-k.right},b.scrollingSpeed,
b.easing));lastScrolledDestiny=f;z(f);A(f,d)}function u(){document.addEventListener?(document.addEventListener("mousewheel",g,!1),document.addEventListener("wheel",g,!1)):document.attachEvent("onmousewheel",g)}function g(c){c=window.event||c;c=Math.max(-1,Math.min(1,c.wheelDelta||-c.deltaY||-c.detail));h||(0>c?a.fn.multiscroll.moveSectionDown():a.fn.multiscroll.moveSectionUp());return!1}function m(c,a,b){c.toggleClass("ms-easing",b);c.css({"-webkit-transform":a,"-moz-transform":a,"-ms-transform":a,
transform:a})}function A(c,d){b.navigation&&(a("#multiscroll-nav").find(".active").removeClass("active"),c?a("#multiscroll-nav").find('a[href="#'+c+'"]').addClass("active"):a("#multiscroll-nav").find("li").eq(d).find("a").addClass("active"))}function z(c){b.menu&&(a(b.menu).find(".active").removeClass("active"),a(b.menu).find('[data-menuanchor="'+c+'"]').addClass("active"))}function y(c){var b=a(".ms-left .ms-section.active").index();c=c.index();return b>c?"up":"down"}function B(){var a=document.createElement("p"),
b,e={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};document.body.insertBefore(a,null);for(var f in e)void 0!==a.style[f]&&(a.style[f]="translate3d(1px,1px,1px)",b=window.getComputedStyle(a).getPropertyValue(e[f]));document.body.removeChild(a);return void 0!==b&&0<b.length&&"none"!==b}function r(a){var d=q;if(b.paddingTop||b.paddingBottom)a=parseInt(a.css("padding-top"))+parseInt(a.css("padding-bottom")),
d=q-a;return d}function C(c){var d=c.originalEvent;c.preventDefault();a(".ms-left .ms-section.active");h||(n=v(d).y,Math.abs(p-n)>a(window).height()/100*b.touchSensitivity&&(p>n?a.fn.multiscroll.moveSectionDown():n>p&&a.fn.multiscroll.moveSectionUp()))}function D(a){p=v(a.originalEvent).y}function v(a){var b=[];window.navigator.msPointerEnabled?(b.y=a.pageY,b.x=a.pageX):(b.y=a.touches[0].pageY,b.x=a.touches[0].pageX);return b}b=a.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,afterLoad:null,onLeave:null,afterRender:null,afterResize:null},b);var E="ontouchstart"in window||0<navigator.msMaxTouchPoints,x=a(".ms-left").find(".ms-section").length,h=!1,l,q=a(window).height();u();E&&(MSPointer=window.PointerEvent?
{down:"pointerdown",move:"pointermove"}:{down:"MSPointerDown",move:"MSPointerMove"},a(document).off("touchstart "+MSPointer.down).on("touchstart "+MSPointer.down,D),a(document).off("touchmove "+MSPointer.move).on("touchmove "+MSPointer.move,C));b.css3&&(b.css3=B());a("html, body").css({overflow:"hidden",height:"100%"});b.navigation&&(a("body").append('<div id="multiscroll-nav"><ul></ul></div>'),l=a("#multiscroll-nav"),l.css("color",b.navigationColor),l.addClass(b.navigationPosition));a(".ms-right, .ms-left").css({width:"50%",
position:"absolute",height:"100%","-ms-touch-action":"none"});a(".ms-right").css({right:"1px",top:"0","-ms-touch-action":"none","touch-action":"none"});a(".ms-left").css({left:"0",top:"0","-ms-touch-action":"none","touch-action":"none"});a(".ms-left .ms-section, .ms-right .ms-section").each(function(){var c=a(this).index();(b.paddingTop||b.paddingBottom)&&a(this).css("padding",b.paddingTop+" 0 "+b.paddingBottom+" 0");"undefined"!==typeof b.sectionsColor[c]&&a(this).css("background-color",b.sectionsColor[c]);
"undefined"!==typeof b.anchors[c]&&a(this).attr("data-anchor",b.anchors[c]);if(b.verticalCentered){var d=a(this);d.addClass("ms-table").wrapInner('<div class="ms-tableCell" style="height: '+r(d)+'px" />')}a(this).closest(".ms-left").length&&b.navigation&&(d="",b.anchors.length&&(d=b.anchors[c]),c=b.navigationTooltips[c],"undefined"===typeof c&&(c=""),b.navigation&&l.find("ul").append('<li data-tooltip="'+c+'"><a href="#'+d+'"><span></span></a></li>'))});a(".ms-right").html(a(".ms-right").find(".ms-section").get().reverse());
a(".ms-left .ms-section, .ms-right .ms-section").each(function(){var c=a(this).index();a(this).css({height:"100%"});!c&&b.navigation&&l.find("li").eq(c).find("a").addClass("active")}).promise().done(function(){a(".ms-left .ms-section.active").length||(a(".ms-right").find(".ms-section").last().addClass("active"),a(".ms-left").find(".ms-section").first().addClass("active"));a.isFunction(b.afterRender)&&b.afterRender.call(this);s();a(window).on("load",function(){var c=window.location.hash.replace("#",
""),b=a('.ms-left .ms-section[data-anchor="'+c+'"]');c.length&&e(b)})});a(window).on("hashchange",function(){var c=window.location.hash.replace("#","");if(c.length){var b=a(".ms-left").find('[data-anchor="'+c+'"]');"undefined"!==typeof lastScrolledDestiny&&c===lastScrolledDestiny||e(b)}});a(document).keydown(function(c){40!=c.which&&38!=c.which||c.preventDefault();if(b.keyboardScrolling&&!h)switch(c.which){case 38:case 33:a.fn.multiscroll.moveSectionUp();break;case 40:case 34:a.fn.multiscroll.moveSectionDown();
break;case 36:a.fn.multiscroll.moveTo(1);break;case 35:a.fn.multiscroll.moveTo(a(".ms-left .ms-section").length)}});a(document).mousedown(function(a){if(1==a.button)return a.preventDefault(),!1});a(document).on("click","#multiscroll-nav a",function(c){c.preventDefault();c=a(this).parent().index();e(a(".ms-left .ms-section").eq(c))});a(document).on({mouseenter:function(){var c=a(this).data("tooltip");a('<div class="multiscroll-tooltip '+b.navigationPosition+'">'+c+"</div>").hide().appendTo(a(this)).fadeIn(200)},
mouseleave:function(){a(this).find(".multiscroll-tooltip").fadeOut(200,function(){a(this).remove()})}},"#multiscroll-nav li");b.normalScrollElements&&(a(document).on("mouseenter",b.normalScrollElements,function(){a.fn.multiscroll.setMouseWheelScrolling(!1)}),a(document).on("mouseleave",b.normalScrollElements,function(){a.fn.multiscroll.setMouseWheelScrolling(!0)}));a(window).resize(function(){w()});a.fn.multiscroll.moveSectionUp=function(){var c=a(".ms-left .ms-section.active").prev(".ms-section");
!c.length&&b.loopTop&&(c=a(".ms-left .ms-section").last());c.length&&e(c)};a.fn.multiscroll.moveSectionDown=function(){var c=a(".ms-left .ms-section.active").next(".ms-section");!c.length&&b.loopBottom&&(c=a(".ms-left .ms-section").first());c.length&&e(c)};a.fn.multiscroll.moveTo=function(c){var b="",b=isNaN(c)?a('.ms-left [data-anchor="'+c+'"]'):a(".ms-left .ms-section").eq(c-1);e(b)};a.fn.multiscroll.setKeyboardScrolling=function(a){b.keyboardScrolling=a};a.fn.multiscroll.setMouseWheelScrolling=
function(a){a?u():document.addEventListener?(document.removeEventListener("mousewheel",g,!1),document.removeEventListener("wheel",g,!1)):document.detachEvent("onmousewheel",g)};a.fn.multiscroll.setScrollingSpeed=function(a){b.scrollingSpeed=a};var p=0,n=0}})(jQuery);