diff --git a/README.md b/README.md index 53ab691..5463d73 100644 --- a/README.md +++ b/README.md @@ -209,11 +209,21 @@ $.fn.pagepiling.moveTo(3); $.fn.pagepiling.moveTo(3); ``` -### setAllowScrolling(boolean) +### setAllowScrolling(boolean, [directions]) Adds or remove the possibility of scrolling through sections by using the mouse wheel/trackpad or touch gestures (which is active by default). +- `directions`: (optional parameter) Admitted values: `all`, `up`, `down`, `left`, `right` or a combination of them separated by commas like `down, right`. It defines the direction for which the scrolling will be enabled or disabled. + ```javascript -$.fn.pagepiling.setAllowScrolling(false); + +//disabling scrolling +$.fn.fullpage.setAllowScrolling(false); + +//disabling scrolling down +$.fn.fullpage.setAllowScrolling(false, 'down'); + +//disabling scrolling down and right +$.fn.fullpage.setAllowScrolling(false, 'down, right'); ``` ### setKeyboardScrolling(boolean) diff --git a/jquery.pagepiling.js b/jquery.pagepiling.js index 0523e7a..276acac 100644 --- a/jquery.pagepiling.js +++ b/jquery.pagepiling.js @@ -18,6 +18,7 @@ var lastAnimation = 0; var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints)); var touchStartY = 0, touchStartX = 0, touchEndY = 0, touchEndX = 0; + var isScrollAllowed = { 'up':true, 'down':true, 'left':true, 'right':true }; //Defines the delay to take place before being able to scroll to the next section //BE CAREFUL! Not recommened to change it under 400 for a good behavior in laptops and @@ -79,8 +80,18 @@ /** * Adds or remove the possiblity of scrolling through sections by using the mouse wheel/trackpad or touch gestures. + * Optionally a second parameter can be used to specify the direction for which the action will be applied. + * + * @param directions string containing the direction or directions separated by comma. */ PP.setAllowScrolling = function (value){ + if(typeof directions != 'undefined'){ + directions = directions.replace(/ /g,'').split(','); + + $.each(directions, function (index, direction){ + setIsScrollable(value, direction); + }); + } if(value){ PP.setMouseWheelScrolling(true); addTouchHandler(); @@ -589,8 +600,10 @@ * by 'automatically' scrolling a section or by using the default and normal scrolling. */ function scrolling(type, scrollable){ - var check; - var scrollSection; + if (!isScrollAllowed[type]){ + return; + } + var check, scrollSection; if(type == 'down'){ check = 'bottom'; @@ -739,6 +752,19 @@ } } + /** + * Set the allowed scroll direction + */ + function setIsScrollable(value, direction){ + switch (direction){ + case 'up': isScrollAllowed.up = value; break; + case 'down': isScrollAllowed.down = value; break; + case 'left': isScrollAllowed.left = value; break; + case 'right': isScrollAllowed.right = value; break; + case 'all': PP.setAllowScrolling(value); + } + } + /* Detecting touch events */ function touchMoveHandler(event){ diff --git a/jquery.pagepiling.min.js b/jquery.pagepiling.min.js index c1b46c4..54a91ca 100644 --- a/jquery.pagepiling.min.js +++ b/jquery.pagepiling.min.js @@ -1,27 +1 @@ -/* =========================================================== - * pagepiling.js 1.5.1 - * - * https://github.com/alvarotrigo/pagePiling.js - * MIT licensed - * - * Copyright (C) 2014 alvarotrigo.com - A project by Alvaro Trigo - * - * ========================================================== */ -(function(b,h,k,y){b.fn.pagepiling=function(J){function K(a){var e=b(".pp-section.active").index(".pp-section");a=a.index(".pp-section");return e>a?"up":"down"}function l(a,e){var d={destination:a,animated:e,activeSection:b(".pp-section.active"),anchorLink:a.data("anchor"),sectionIndex:a.index(".pp-section"),toMove:a,yMovement:K(a),leavingSection:b(".pp-section.active").index(".pp-section")+1};d.activeSection.is(a)||("undefined"===typeof d.animated&&(d.animated=!0),"undefined"!==typeof d.anchorLink&& -L(d.anchorLink,d.sectionIndex),d.destination.addClass("active").siblings().removeClass("active"),d.sectionsToMove=M(d),"down"===d.yMovement?(d.translate3d="vertical"!==c.direction?"translate3d(-100%, 0px, 0px)":"translate3d(0px, -100%, 0px)",d.scrolling="-100%",c.css3||d.sectionsToMove.each(function(a){a!=d.activeSection.index(".pp-section")&&b(this).css(u(d.scrolling))}),d.animateSection=d.activeSection):(d.translate3d="translate3d(0px, 0px, 0px)",d.scrolling="0",d.animateSection=a),b.isFunction(c.onLeave)&& -c.onLeave.call(this,d.leavingSection,d.sectionIndex+1,d.yMovement),N(d),O(d.anchorLink),P(d.anchorLink,d.sectionIndex),z=d.anchorLink,A=(new Date).getTime())}function N(a){c.css3?(B(a.animateSection,a.translate3d,a.animated),a.sectionsToMove.each(function(){B(b(this),a.translate3d,a.animated)}),setTimeout(function(){v(a)},c.scrollingSpeed)):(a.scrollOptions=u(a.scrolling),a.animated?a.animateSection.animate(a.scrollOptions,c.scrollingSpeed,c.easing,function(){C(a);v(a)}):(a.animateSection.css(u(a.scrolling)), -setTimeout(function(){C(a);v(a)},400)))}function v(a){b.isFunction(c.afterLoad)&&c.afterLoad.call(this,a.anchorLink,a.sectionIndex+1)}function M(a){return"down"===a.yMovement?b(".pp-section").map(function(e){if(ea.destination.index(".pp-section"))return b(this)})}function C(a){"up"===a.yMovement&&a.sectionsToMove.each(function(e){b(this).css(u(a.scrolling))})}function u(a){return"vertical"===c.direction?{top:a}: -{left:a}}function L(a,b){c.anchors.length?(location.hash=a,D(location.hash)):D(String(b))}function D(a){a=a.replace("#","");b("body")[0].className=b("body")[0].className.replace(/\b\s?pp-viewing-[^\s]+\b/g,"");b("body").addClass("pp-viewing-"+a)}function w(){return(new Date).getTime()-A<600+c.scrollingSpeed?!0:!1}function B(a,b,c){a.toggleClass("pp-easing",c);a.css({"-webkit-transform":b,"-moz-transform":b,"-ms-transform":b,transform:b})}function m(a){if(!w()){a=k.event||a;a=Math.max(-1,Math.min(1, -a.wheelDelta||-a.deltaY||-a.detail));var e=b(".pp-section.active").filter(".pp-scrollable");0>a?n("down",e):n("up",e);return!1}}function n(a,b){var c,g;"down"==a?(c="bottom",g=f.moveSectionDown):(c="top",g=f.moveSectionUp);if(0=b[0].scrollHeight:void 0,c)g();else return!0;else g()}function E(){return k.PointerEvent?{down:"pointerdown",move:"pointermove",up:"pointerup"}:{down:"MSPointerDown",move:"MSPointerMove",up:"MSPointerUp"}} -function F(a){var b=[];b.y="undefined"!==typeof a.pageY&&(a.pageY||a.pageX)?a.pageY:a.touches[0].pageY;b.x="undefined"!==typeof a.pageX&&(a.pageY||a.pageX)?a.pageX:a.touches[0].pageX;return b}function G(a){return"undefined"===typeof a.pointerType||"mouse"!=a.pointerType}function Q(a){a=a.originalEvent;G(a)&&(a=F(a),p=a.y,q=a.x)}function R(a){var e=a.originalEvent;!H(a.target)&&G(e)&&(a.preventDefault(),a=b(".pp-section.active").filter(".pp-scrollable"),w()||(e=F(e),r=e.y,t=e.x,"horizontal"===c.direction&& -Math.abs(q-t)>Math.abs(p-r)?Math.abs(q-t)>g.width()/100*c.touchSensitivity&&(q>t?n("down",a):t>q&&n("up",a)):Math.abs(p-r)>g.height()/100*c.touchSensitivity&&(p>r?n("down",a):r>p&&n("up",a))))}function H(a,e){e=e||0;var d=b(a).parent();return e
    ');var a=b("#pp-nav");a.css("color",c.navigation.textColor);a.addClass(c.navigation.position); -for(var e=0;e')}a.find("span").css("border-color",c.navigation.bulletsColor)}function P(a,e){c.navigation&&(b("#pp-nav").find(".active").removeClass("active"),a?b("#pp-nav").find('a[href="#'+a+'"]').addClass("active"):b("#pp-nav").find("li").eq(e).find("a").addClass("active"))} -function O(a){c.menu&&(b(c.menu).find(".active").removeClass("active"),b(c.menu).find('[data-menuanchor="'+a+'"]').addClass("active"))}function T(){var a=h.createElement("p"),b,c={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};h.body.insertBefore(a,null);for(var f in c)a.style[f]!==y&&(a.style[f]="translate3d(1px,1px,1px)",b=k.getComputedStyle(a).getPropertyValue(c[f]));h.body.removeChild(a);return b!== -y&&0');--x}).promise().done(function(){c.navigation&& -(b("#pp-nav").css("margin-top","-"+b("#pp-nav").height()/2+"px"),b("#pp-nav").find("li").eq(b(".pp-section.active").index(".pp-section")).find("a").addClass("active"));b(k).on("load",function(){var a=k.location.hash.replace("#",""),a=b('.pp-section[data-anchor="'+a+'"]');0'+a+"").hide().appendTo(b(this)).fadeIn(200)},mouseleave:function(){b(this).find(".pp-tooltip").fadeOut(200,function(){b(this).remove()})}},"#pp-nav li")}})(jQuery,document,window); \ No newline at end of file +(function(c,a,b,d){c.fn.pagepiling=function(I){var f=c.fn.pagepiling;var O=c(this);var m;var M=0;var p=(("ontouchstart" in b)||(navigator.msMaxTouchPoints>0)||(navigator.maxTouchPoints));var D=0,G=0,g=0,i=0;var e={up:true,down:true,left:true,right:true};var B=600;var H=c.extend(true,{direction:"vertical",menu:null,verticalCentered:true,sectionsColor:[],anchors:[],scrollingSpeed:700,easing:"easeInQuart",loopBottom:false,loopTop:false,css3:true,navigation:{textColor:"#000",bulletsColor:"#000",position:"right",tooltips:[]},normalScrollElements:null,normalScrollElementTouchThreshold:5,touchSensitivity:5,keyboardScrolling:true,sectionSelector:".section",animateAnchor:false,afterLoad:null,onLeave:null,afterRender:null},I);c.extend(c.easing,{easeInQuart:function(ad,ae,ac,ag,af){return ag*(ae/=af)*ae*ae*ae+ac}});f.setScrollingSpeed=function(ac){H.scrollingSpeed=ac};f.setMouseWheelScrolling=function(ac){if(ac){L()}else{r()}};f.setAllowScrolling=function(ac){if(typeof directions!="undefined"){directions=directions.replace(/ /g,"").split(",");c.each(directions,function(ad,ae){V(ac,ae)})}if(ac){f.setMouseWheelScrolling(true);o()}else{f.setMouseWheelScrolling(false);Z()}};f.setKeyboardScrolling=function(ac){H.keyboardScrolling=ac};f.moveSectionUp=function(){var ac=c(".pp-section.active").prev(".pp-section");if(!ac.length&&H.loopTop){ac=c(".pp-section").last()}if(ac.length){x(ac)}};f.moveSectionDown=function(){var ac=c(".pp-section.active").next(".pp-section");if(!ac.length&&H.loopBottom){ac=c(".pp-section").first()}if(ac.length){x(ac)}};f.moveTo=function(ad){var ac="";if(isNaN(ad)){ac=c('[data-anchor="'+ad+'"]')}else{ac=c(".pp-section").eq((ad-1))}if(ac.length>0){x(ac)}};c(H.sectionSelector).each(function(){c(this).addClass("pp-section")});if(H.css3){H.css3=K()}c(O).css({overflow:"hidden","-ms-touch-action":"none","touch-action":"none"});f.setAllowScrolling(true);if(!c.isEmptyObject(H.navigation)){W()}var u=c(".pp-section").length;c(".pp-section").each(function(ac){c(this).data("data-index",ac);c(this).css("z-index",u);if(!ac&&c(".pp-section.active").length===0){c(this).addClass("active")}if(typeof H.anchors[ac]!=="undefined"){c(this).attr("data-anchor",H.anchors[ac])}if(typeof H.sectionsColor[ac]!=="undefined"){c(this).css("background-color",H.sectionsColor[ac])}if(H.verticalCentered&&!c(this).hasClass("pp-scrollable")){z(c(this))}u=u-1}).promise().done(function(){if(H.navigation){c("#pp-nav").css("margin-top","-"+(c("#pp-nav").height()/2)+"px");c("#pp-nav").find("li").eq(c(".pp-section.active").index(".pp-section")).find("a").addClass("active")}c(b).on("load",function(){h()});c.isFunction(H.afterRender)&&H.afterRender.call(this)});function z(ac){ac.addClass("pp-table").wrapInner('
    ')}function N(ad){var ac=c(".pp-section.active").index(".pp-section");var ae=ad.index(".pp-section");if(ac>ae){return"up"}return"down"}function x(ac,af){var ad={destination:ac,animated:af,activeSection:c(".pp-section.active"),anchorLink:ac.data("anchor"),sectionIndex:ac.index(".pp-section"),toMove:ac,yMovement:N(ac),leavingSection:c(".pp-section.active").index(".pp-section")+1};if(ad.activeSection.is(ac)){return}if(typeof ad.animated==="undefined"){ad.animated=true}if(typeof ad.anchorLink!=="undefined"){A(ad.anchorLink,ad.sectionIndex)}ad.destination.addClass("active").siblings().removeClass("active");ad.sectionsToMove=P(ad);if(ad.yMovement==="down"){ad.translate3d=y();ad.scrolling="-100%";if(!H.css3){ad.sectionsToMove.each(function(ag){if(ag!=ad.activeSection.index(".pp-section")){c(this).css(s(ad.scrolling))}})}ad.animateSection=ad.activeSection}else{ad.translate3d="translate3d(0px, 0px, 0px)";ad.scrolling="0";ad.animateSection=ac}c.isFunction(H.onLeave)&&H.onLeave.call(this,ad.leavingSection,(ad.sectionIndex+1),ad.yMovement);j(ad);k(ad.anchorLink);v(ad.anchorLink,ad.sectionIndex);m=ad.anchorLink;var ae=new Date().getTime();M=ae}function j(ac){if(H.css3){T(ac.animateSection,ac.translate3d,ac.animated);ac.sectionsToMove.each(function(){T(c(this),ac.translate3d,ac.animated)});setTimeout(function(){S(ac)},H.scrollingSpeed)}else{ac.scrollOptions=s(ac.scrolling);if(ac.animated){ac.animateSection.animate(ac.scrollOptions,H.scrollingSpeed,H.easing,function(){aa(ac);S(ac)})}else{ac.animateSection.css(s(ac.scrolling));setTimeout(function(){aa(ac);S(ac)},400)}}}function S(ac){c.isFunction(H.afterLoad)&&H.afterLoad.call(this,ac.anchorLink,(ac.sectionIndex+1))}function P(ac){var ad;if(ac.yMovement==="down"){ad=c(".pp-section").map(function(ae){if(aeac.destination.index(".pp-section")){return c(this)}})}return ad}function aa(ac){if(ac.yMovement==="up"){ac.sectionsToMove.each(function(ad){c(this).css(s(ac.scrolling))})}}function s(ac){if(H.direction==="vertical"){return{top:ac}}return{left:ac}}function E(ac,ad){if(H.css3){T(ac,y(),false)}else{ac.css(s(ad))}}function A(ac,ad){if(H.anchors.length){location.hash=ac;Q(location.hash)}else{Q(String(ad))}}function Q(ac){ac=ac.replace("#","");c("body")[0].className=c("body")[0].className.replace(/\b\s?pp-viewing-[^\s]+\b/g,"");c("body").addClass("pp-viewing-"+ac)}function h(){var ad=b.location.hash.replace("#","");var ac=ad;var ae=c('.pp-section[data-anchor="'+ac+'"]');if(ae.length>0){x(ae,H.animateAnchor)}}function l(){var ac=new Date().getTime();if(ac-M0){if(U(ac,af)){ad()}else{return true}}else{ad()}}function U(ac,ad){if(ac==="top"){return !ad.scrollTop()}else{if(ac==="bottom"){return ad.scrollTop()+1+ad.innerHeight()>=ad[0].scrollHeight}}}function R(ac){return ac.filter(".pp-scrollable")}function r(){if(O.get(0).addEventListener){O.get(0).removeEventListener("mousewheel",X,false);O.get(0).removeEventListener("wheel",X,false)}else{O.get(0).detachEvent("onmousewheel",X)}}function L(){if(O.get(0).addEventListener){O.get(0).addEventListener("mousewheel",X,false);O.get(0).addEventListener("wheel",X,false)}else{O.get(0).attachEvent("onmousewheel",X)}}function o(){if(p){var ac=t();O.off("touchstart "+ac.down).on("touchstart "+ac.down,C);O.off("touchmove "+ac.move).on("touchmove "+ac.move,J)}}function Z(){if(p){var ac=t();O.off("touchstart "+ac.down);O.off("touchmove "+ac.move)}}function t(){var ac;if(b.PointerEvent){ac={down:"pointerdown",move:"pointermove",up:"pointerup"}}else{ac={down:"MSPointerDown",move:"MSPointerMove",up:"MSPointerUp"}}return ac}function w(ad){var ac=new Array();ac.y=(typeof ad.pageY!=="undefined"&&(ad.pageY||ad.pageX)?ad.pageY:ad.touches[0].pageY);ac.x=(typeof ad.pageX!=="undefined"&&(ad.pageY||ad.pageX)?ad.pageX:ad.touches[0].pageX);return ac}function F(ac){return typeof ac.pointerType==="undefined"||ac.pointerType!="mouse"}function C(ad){var ae=ad.originalEvent;if(F(ae)){var ac=w(ae);D=ac.y;G=ac.x}}function V(ac,ad){switch(ad){case"up":e.up=ac;break;case"down":e.down=ac;break;case"left":e.left=ac;break;case"right":e.right=ac;break;case"all":f.setAllowScrolling(ac)}}function J(ae){var ag=ae.originalEvent;if(!q(ae.target)&&F(ag)){ae.preventDefault();var ac=c(".pp-section.active");var af=R(ac);if(!l()){var ad=w(ag);g=ad.y;i=ad.x;if(H.direction==="horizontal"&&Math.abs(G-i)>(Math.abs(D-g))){if(Math.abs(G-i)>(O.width()/100*H.touchSensitivity)){if(G>i){ab("down",af)}else{if(i>G){ab("up",af)}}}}else{if(Math.abs(D-g)>(O.height()/100*H.touchSensitivity)){if(D>g){ab("down",af)}else{if(g>D){ab("up",af)}}}}}}}function q(ae,ac){ac=ac||0;var ad=c(ae).parent();if(ac
      ');var af=c("#pp-nav");af.css("color",H.navigation.textColor);af.addClass(H.navigation.position);for(var ac=0;ac')}af.find("span").css("border-color",H.navigation.bulletsColor)}c(a).on("click touchstart","#pp-nav a",function(ad){ad.preventDefault();var ac=c(this).parent().index();x(c(".pp-section").eq(ac))});c(a).on({mouseenter:function(){var ac=c(this).data("tooltip");c('
      '+ac+"
      ").hide().appendTo(c(this)).fadeIn(200)},mouseleave:function(){c(this).find(".pp-tooltip").fadeOut(200,function(){c(this).remove()})}},"#pp-nav li");function v(ac,ad){if(H.navigation){c("#pp-nav").find(".active").removeClass("active");if(ac){c("#pp-nav").find('a[href="#'+ac+'"]').addClass("active")}else{c("#pp-nav").find("li").eq(ad).find("a").addClass("active")}}}function k(ac){if(H.menu){c(H.menu).find(".active").removeClass("active");c(H.menu).find('[data-menuanchor="'+ac+'"]').addClass("active")}}function K(){var ae=a.createElement("p"),af,ad={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};a.body.insertBefore(ae,null);for(var ac in ad){if(ae.style[ac]!==d){ae.style[ac]="translate3d(1px,1px,1px)";af=b.getComputedStyle(ae).getPropertyValue(ad[ac])}}a.body.removeChild(ae);return(af!==d&&af.length>0&&af!=="none")}function y(){if(H.direction!=="vertical"){return"translate3d(-100%, 0px, 0px)"}return"translate3d(0px, -100%, 0px)"}}})(jQuery,document,window); \ No newline at end of file