Skip to content

Commit

Permalink
Adds touch scroll.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed Apr 5, 2013
1 parent 50d567f commit e6837b4
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions lib/gutenberg/assets/js/typeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ function goto_page(page_number) {
$('#page-' + next_page + ' .divider').show();
}

function scroll_up() {
function scroll_up(amount) {
page = $('#page-' + next_page);
page.css('height', '-=50');
page.css('height', '-=' + amount);

if (page.height() <= 0) {
if (next_page > 1) {
Expand All @@ -132,9 +132,9 @@ function scroll_up() {
}
}

function scroll_down() {
function scroll_down(amount) {
page = $('#page-' + next_page);
page.css('height', '+=50');
page.css('height', '+=' + amount);

if (page.height() > $(window).height()) {
if (next_page > 1) {
Expand Down Expand Up @@ -369,12 +369,35 @@ $('body').on('swiperight', function(e) {
goto_page(next_page);
});

var start_height;
var start_pos;
$('body').on('movestart', function(e) {
start_height = $('#page-' + next_page).height();
start_pos = e.startY;
});

$('body').on('move', function(e) {
// Calculate deltaY ourselves to increase accuracy
deltaY = e.pageY - start_pos;

var last_page = next_page;
if (deltaY > 0) {
scroll_down(deltaY);
}
else if (deltaY < 0) {
scroll_up(-deltaY);
}

start_pos = e.pageY;
start_height = $('#page-' + next_page).height();
});

$('body').mousewheel(function(event, delta, deltaX, deltaY) {
if (deltaY > 0) {
scroll_up();
scroll_up(50);
}
else if (deltaY < 0) {
scroll_down();
scroll_down(50);
}
});

Expand Down

0 comments on commit e6837b4

Please sign in to comment.