Skip to content
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

Added onScrollEnd hook #27

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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
bower_components
12 changes: 10 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ <h2>Horizontal scroller</h2>
<script>
$(document).ready(function() {
// Initialize scrollers.
$('.demo1').TrackpadScrollEmulator();
$('.demo2').TrackpadScrollEmulator();
$('.demo1').TrackpadScrollEmulator({
onScrollEnd: function() {
alert('at the end');
}
});
$('.demo2').TrackpadScrollEmulator({
onScrollEnd: function() {
alert('at the end');
}
});
// Demonstration of changing the vertical scroller content and dimensions.
$('.add-more').on('click', function(e){
e.preventDefault();
Expand Down
14 changes: 14 additions & 0 deletions jquery.trackpad-scroll-emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@
*/
function onScrolled(e) {
flashScrollbar();
checkScrollEnd();
}

function checkScrollEnd() {
var contentSize = sizeAttr === 'height' ? $contentEl.outerHeight() : $contentEl.outerWidth();
var scrollOffset = $scrollContentEl[scrollOffsetAttr](); // Either scrollTop() or scrollLeft().
var scrollbarSize = $scrollbarEl[sizeAttr]();

var endReached = scrollOffset + scrollbarSize + options.scrollBuffer >= contentSize;
if (endReached) {
hook('onScrollEnd');
}
}

/**
Expand Down Expand Up @@ -322,6 +334,8 @@
$.fn[pluginName].defaults = {
onInit: function() {},
onDestroy: function() {},
onScrollEnd: function() {},
scrollBuffer: 50,
wrapContent: true,
autoHide: true
};
Expand Down
2 changes: 1 addition & 1 deletion jquery.trackpad-scroll-emulator.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.