Last active
August 29, 2015 14:25
-
-
Save julienetie/86ac394ec41f1271ff0a to your computer and use it in GitHub Desktop.
Cleanly detect requestAnimationFrame iOS 6 bug without the use of user-agent sniffing.
This file contains 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
/** | |
* hasIOS6RequestAnimationFrameBug. | |
* @See {@Link https://gist.github.com/julienetie/86ac394ec41f1271ff0a} - Commentary. | |
* @Copyright 2015 - Julien Etienne. | |
* @License: MIT. | |
*/ | |
function hasIOS6RequestAnimationFrameBug() { | |
var hasMobileDeviceWidth = screen.width <= 768 ? true : false, | |
requiresWebkitRequestAnimationFrame = !((window.webkitRequestAnimationFrame && window.requestAnimationFrame)), | |
hasNoNavigationTiming = window.performance ? false : true; | |
if (requiresWebkitRequestAnimationFrame && hasMobileDeviceWidth && hasNoNavigationTiming) { | |
if (window.webkitRequestAnimationFrame || window.requestAnimationFrame) { | |
console.warn('This device may contain the iOS v6x webkitRequestAnimationFrame timing bug. For timing, please use an alternative such as the "setTimeout()" or "setInterval()" API'); | |
return true; | |
} else { | |
console.info('hasIOS6RequestAnimationFrameBug is not applicable for this device'); | |
return false; | |
} | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A clean solution for the iOS 6 timing bug (2015)
Tested on all major mobile and desktop browsers.
Below is a quick copy and paste demo. Here's a fiddle: http://jsfiddle.net/julienetienne/je1kt6L2/8/