// Jugez l'état de l'écran horizontal et vertical du téléphone mobile: fonction HensHuping () {if (window.orientation == 180 || window.orientation == 0) {alert ("statut de l'écran vertical!")} If (window.orientation == 90 || window.orientation == - 90) {alert ("Horizontal Screen Status! ")}} window.addeventListener (" OnOrientationChange "dans Window?" OrientationChange ":" Resize ", HensHuping, false);// Les navigateurs mobiles prennent généralement en charge le paramètre Window. Grâce à ce paramètre, vous pouvez déterminer si le téléphone est dans un état d'écran horizontal ou vertical.
Par conséquent, les procédures correspondantes sont exécutées en fonction des besoins réels. En ajoutant l'événement d'écoute On OoritationChange, vous pouvez l'exécuter.
Dans le développement des pages Web iPad et iPhone, nous devrons peut-être juger s'il s'agit d'un écran horizontal ou d'un écran vertical.
Ce qui suit est une description de la façon d'utiliser JQuery pour déterminer si l'iPad, l'iPhone et Android sont horizontaux ou verticaux.
fonction orientée () {if (window.orientation == 90 || window.orientation == -90) {// iPad, écran vertical iPhone; Andriod Horizontal Screen $ ("Body"). Att ("Class", "paysage"); orientation = 'paysage'; return false;} else if (window.orientation == 0 || window.orientation == 180) {// iPad, écran horizontal iPhone; Andriod Vertical Screen $ ("Body"). Att ("Class", "Portrait"); orientation = 'portrait'; return false;}} // call $ (function () {orient ();}); // appelle $ (fenêtre) lorsque l'utilisateur modifie l'écran direction.bind ('orientationchange', function (e) {orient ();});La valeur de la fenêtre. Orientée correspondant à la direction de l'écran:
iPad: écran horizontal 90 ou -90
iPad: 0 ou 180 écran vertical
Android: écran horizontal 0 ou 180
Android: écran vertical 90 ou -90
Ce qui précède est le problème de l'utilisation de JavaScript pour déterminer si un navigateur mobile est horizontal ou vertical. J'espère que ce sera utile à tout le monde. Si vous avez des questions, veuillez me laisser un message et l'éditeur répondra à tout le monde à temps. Merci beaucoup pour votre soutien au site Web Wulin.com!