Skip to content

jlubean/orientationchange

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

orientationchange Polyfill

This polyfill allows you to use "window.orientation" and to bind to the "orientationchange" event. It has no dependencies on any libraries, but has support for using jQuery to bind to the "orientationchange" event.

Because IE8 does not allow you to use attachEvent / fireEvent for custom events, you have to set the window.onorientationchange function:

function handler() {
	if(window.orientation == 0 || window.orientation == 180) {
		// Do something useful in portrait mode
	} else {
		// Do something useful in landscape mode
	}
}

if(window.addEventListener) {
	window.addEventListener("orientationchange", handler, false);
} else {
	window.onorientationchange = handler;
}

If you use jQuery:

$(window).on('orientationchange', function() {
	if(window.orientation == 0 || window.orientation == 180) {
		// Do something useful in portrait mode
	} else {
		// Do something useful in landscape mode
	}
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published