Created
March 15, 2012 07:22
-
-
Save oosugi20/2042711 to your computer and use it in GitHub Desktop.
スマホの縦横検出
This file contains hidden or 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
/** | |
* 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