Created
December 12, 2014 12:07
-
-
Save arielsalminen/01a531e3d6654bd129e4 to your computer and use it in GitHub Desktop.
Fix iOS7 & iOS8 page visibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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