Skip to content

Instantly share code, notes, and snippets.

@arielsalminen
Created December 12, 2014 12:07
Show Gist options
  • Save arielsalminen/01a531e3d6654bd129e4 to your computer and use it in GitHub Desktop.
Save arielsalminen/01a531e3d6654bd129e4 to your computer and use it in GitHub Desktop.
Fix iOS7 & iOS8 page visibility
var pageVisibilityTimer = false;
function isIOS7orNewer() {
return (/(iphone|ipad|ipod).+(os\s7|os\s8)/i).test(navigator.userAgent);
}
function pageVisibilityFix() {
pageVisibilityTimer = window.setInterval(function() {
window.scrollTo(document.body.scrollLeft, document.body.scrollTop);
}, 500);
}
function stopPageVisibilityFix() {
if (pageVisibilityTimer) {
window.clearInterval(pageVisibilityTimer);
pageVisibilityTimer = false;
}
}
function startPageVisibilityFix() {
if (isIOS7orNewer()) pageVisibilityFix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment