Skip to content

Feature to cancelling the move before it takes place #153

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 1 commit 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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Example:
```

### onLeave (`index`, `nextIndex`, `direction`)
This callback is fired once the user leaves a section, in the transition to the new section.
This callback is fired once the user leaves a section, in the transition to the new section. Returning `false` will cancel the move before it takes place.

Parameters:

Expand All @@ -294,6 +294,22 @@ Example:
});
```

#### Cancelling the move before it takes place

You can cancel the move by returning `false` on the `onLeave` callback:

Example:

```javascript
$('#pagepiling').pagepiling({
onLeave: function(index, nextIndex, direction){
//it won't move if the destination is the 3rd section
if(nextIndex == 3){
return false;
}
}
});
```

### afterRender()
This callback is fired just after the structure of the page is generated. This is the callback you want to use to initialize other plugins or fire any code which requires the document to be ready (as this plugin modifies the DOM to create the resulting structure).
Expand Down
10 changes: 7 additions & 3 deletions dist/jquery.pagepiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@
setURLHash(v.anchorLink, v.sectionIndex);
}

if ($.isFunction(options.onLeave)) {
if (options.onLeave.call(this, v.leavingSection, (v.sectionIndex + 1), v.yMovement) === false) {
return;
}
}

v.destination.addClass('active').siblings().removeClass('active');

v.sectionsToMove = getSectionsToMove(v);
Expand Down Expand Up @@ -284,8 +290,6 @@
v.animateSection = destination;
}

$.isFunction(options.onLeave) && options.onLeave.call(this, v.leavingSection, (v.sectionIndex + 1), v.yMovement);

performMovement(v);

activateMenuElement(v.anchorLink);
Expand Down Expand Up @@ -973,4 +977,4 @@
}

};
})(jQuery, document, window);
})(jQuery, document, window);
Loading