diff --git a/r2-streamer-swift/Resources/scripts/utils.js b/r2-streamer-swift/Resources/scripts/utils.js index 58345291..d533311d 100644 --- a/r2-streamer-swift/Resources/scripts/utils.js +++ b/r2-streamer-swift/Resources/scripts/utils.js @@ -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; @@ -37,7 +43,6 @@ var readium = (function() { function orientationChanged() { maxScreenX = (window.orientation === 0 || window.orientation == 180) ? screen.width : screen.height; - snapCurrentPosition(); } function isScrollModeEnabled() { @@ -122,6 +127,9 @@ var readium = (function() { } function snapCurrentPosition() { + if (isScrollModeEnabled()) { + return; + } var currentOffset = window.scrollX; var currentOffsetSnapped = snapOffset(currentOffset + 1);