Home >Web Front-end >JS Tutorial >JavaScript function to determine the horizontal and vertical screen modes of iphone/android phones_javascript skills

JavaScript function to determine the horizontal and vertical screen modes of iphone/android phones_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:58:13997browse

After checking a lot of information, the final conclusion is as follows:

Copy code The code is as follows:

function orientationChange (){
switch(window.orientation) {
case 0: // Portrait
case 180: // Upside-down Portrait
// Javascript to setup Portrait view
break;
case -90: // Landscape: turned 90 degrees counter-clockwise
case 90: // Landscape: turned 90 degrees clockwise
// Javascript to steup Landscape view
break;
}
}
window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", orientationChange, false);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn