Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Last active August 29, 2015 14:03
Show Gist options
  • Save gabrielschulhof/35042b4445c3771827ed to your computer and use it in GitHub Desktop.
Save gabrielschulhof/35042b4445c3771827ed to your computer and use it in GitHub Desktop.
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Trigger "pagebottomreached" when the user scrolls to the bottom
//>>label: Page Scrolling
//>>group: Core
define( [ "jquery", "./page", "../events/touch" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {
$.widget( "mobile.page", $.mobile.page, {
_create: function() {
this._super();
this._on( this.document, {
"scrollstop": "_handleScrollStop"
});
},
_handleScrollStop: function() {
var screenHeight, header, scrolled, footer, scrollEnd, activePage;
if ( this.element.hasClass( "ui-page-active" ) ) {
activePage = this.element;
screenHeight = $.mobile.getScreenHeight();
contentHeight = $(".ui-content", activePage).outerHeight();
header = $(".ui-header", activePage).outerHeight() - 1;
scrolled = $(window).scrollTop();
footer = $(".ui-footer", activePage).outerHeight() - 1;
scrollEnd = contentHeight - screenHeight + header + footer;
$(".ui-btn-left", activePage).text("Scrolled: " + scrolled);
$(".ui-btn-right", activePage).text("ScrollEnd: " + scrollEnd);
if ( scrolled >= scrollEnd) {
this._trigger( "bottomreached" );
}
}
}
});
})( jQuery );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment