Skip to content

Instantly share code, notes, and snippets.

@lylijincheng
Created August 19, 2013 07:07
Show Gist options
  • Save lylijincheng/6266390 to your computer and use it in GitHub Desktop.
Save lylijincheng/6266390 to your computer and use it in GitHub Desktop.
orientationchange on iOS and Android.
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