//Judge the horizontal and vertical screen status of the mobile phone: function henshuping(){if(window.orientation==180||window.orientation==0){alert("vertical screen status!")}if(window.orientation==90||window.orientation==-90){alert("horizontal screen status!")}}window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", henshuping, false);//Mobile browsers generally support the window.orientation parameter. Through this parameter, you can determine whether the phone is in a horizontal or vertical screen state.
Therefore, the corresponding procedures are executed according to actual needs. By adding the listening event onorientationchange, you can execute it.
In the development of iPad and iPhone web pages, we may need to judge whether it is a horizontal screen or a vertical screen.
The following is a description of how to use jQuery to determine whether iPad, iPhone, and Android are horizontal or vertical.
function oriented() {if (window.orientation == 90 || window.orientation == -90) {//ipad, iphone vertical screen; Andriod horizontal screen $("body").attr("class", "landscape"); orientation = 'landscape';return false;}else if (window.orientation == 0 || window.orientation == 180) {//ipad, iphone horizontal screen; Andriod vertical screen $("body").attr("class", "portrait"); orientation = 'portrait';return false;}}//Call $(function(){orient();});//Call $(window) when the user changes the screen direction.bind( 'orientationchange', function(e){orient();});The window.orientation value corresponding to the screen direction:
ipad: 90 or -90 horizontal screen
ipad: 0 or 180 vertical screen
Android: 0 or 180 horizontal screen
Android: 90 or -90 vertical screen
The above is the problem of using JavaScript to determine whether a mobile browser is horizontal or vertical. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!