Skip to content

Added ability to specify direction to the 'setAllowScrolling' method. #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 28 additions & 2 deletions jquery.pagepiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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){
Expand Down
Loading