Skip to content

Instantly share code, notes, and snippets.

@oosugi20
Created March 15, 2012 07:22
Show Gist options
  • Save oosugi20/2042711 to your computer and use it in GitHub Desktop.
Save oosugi20/2042711 to your computer and use it in GitHub Desktop.
スマホの縦横検出
/**
* orientation
* デバイスの向きに合わせてhtml要素にclassを付与
* * 縦:orientationV
* * 横:orientationH
*/
var orientation = (function () {
var $window, $body;
var orientation = {
/**
* changeClass
*/
changeClass: function () {
if (Math.abs(window.orientation) === 90) {
$html
.removeClass('orientationV')
.addClass('orientationH');
}
else {
$html
.removeClass('orientationH')
.addClass('orientationV');
}
}
};
$(function () {
$window = $(window);
$html = $('html');
// init
orientation.changeClass();
// bind
$window.on('orientationchange', function () {
orientation.changeClass();
});
});
return orientation;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment