Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #116 from readium/fixes/scrollmode
Browse files Browse the repository at this point in the history
Fix scroll mode positioning
  • Loading branch information
aferditamuriqi authored Jun 17, 2019
2 parents 44e59ae + ed5a87f commit ba6ff6d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions r2-streamer-swift/Resources/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ var readium = (function() {

// Notify native code that the page has loaded.
window.addEventListener("load", function(){ // on page load
// Notify native code that the page is loaded.
webkit.messageHandlers.didLoad.postMessage("");
window.addEventListener("orientationchange", orientationChanged);
window.addEventListener("orientationchange", function() {
orientationChanged();
snapCurrentPosition();
});
orientationChanged();

// Notify native code that the page is loaded after the page is rendered.
window.requestAnimationFrame(function() {
webkit.messageHandlers.didLoad.postMessage("");
});
}, false);

var last_known_scrollX_position = 0;
Expand Down Expand Up @@ -37,7 +43,6 @@ var readium = (function() {

function orientationChanged() {
maxScreenX = (window.orientation === 0 || window.orientation == 180) ? screen.width : screen.height;
snapCurrentPosition();
}

function isScrollModeEnabled() {
Expand Down Expand Up @@ -122,6 +127,9 @@ var readium = (function() {
}

function snapCurrentPosition() {
if (isScrollModeEnabled()) {
return;
}
var currentOffset = window.scrollX;
var currentOffsetSnapped = snapOffset(currentOffset + 1);

Expand Down

0 comments on commit ba6ff6d

Please sign in to comment.