Created
August 19, 2013 07:07
-
-
Save lylijincheng/6266390 to your computer and use it in GitHub Desktop.
orientationchange on iOS and Android.
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
function orientationchangeevent(fn, context) { | |
return function() { | |
var args; | |
if (context.orientationchangeeventTimeout) { | |
clearTimeout(context.orientationchangeeventTimeout); | |
} | |
args = [].slice.call(arguments); | |
context.orientationchangeeventTimeout = setTimeout(bind(function() { | |
var orientation = window.orientation; | |
if (orientation !== context.lastOrientation) { | |
fn.apply(context, args); | |
} | |
context.lastOrientation = orientation; | |
}, context), /Android/.test(navigator.userAgent) ? 500 : 0); | |
}; | |
function bind(fn, scope) { | |
return fn.bind ? fn.bind(scope) : function() { | |
fn.apply(scope, arguments); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment