var checkorientation = (function () {var win = $ (window), get_orientation, Last_orientation, Init Ial_orientation_is_landscape, Initial_orientation_is_default, Portrait_map = {"0": true, "+": true}, WW, WH, landscape_threshold; if (window.orientation!== undefined) {ww = Window.innerwidth | | win.width (); WH = Window.innerheight | | Win.height (); Landscape_threshold = 50; Initial_orientation_is_landscape = WW > WH && (WW-WH) > Landscape_threshold; Initial_orientation_is_default = portrait_map[Window.orientation]; (The initial is the horizontal screen, the direction is 0 or the *or*), the initial is the vertical screen, the direction is 90 or -90, we//need to adjust Portrait_map if ((initial_orientation_is_l Andscape && initial_orientation_is_default) | | (!initial_orientation_is_landscape &&!initial_orientation_is_default)) {Portrait_map = {" -90": True, "n": true}; }}/** * is judged to be in the same screen * @return{[Type]} [Description] */function get_orientation () {var isportrait = true, Elem = document.documentelement; if (window.orientation!== undefined) {isportrait = portrait_map[window.orientation]; } else {isportrait = Elem && Elem.clientwidth/elem.clientheight < 1.1; } return isportrait? "Portrait": "Landscape"; } last_orientation = Get_orientation (); function handler () {var orientation = get_orientation (); if (orientation!== last_orientation) {last_orientation = orientation; Win.trigger (' Orientation:change ', [last_orientation]);//Borrow Zepto Trigger event}} window.addeventlistener ("Onorien Tationchange "in Window? "Orientationchange": "Resize", Handler, false); return {Get_orientation:get_orientation}}) ();
How to use:
(1) checkorientation.get_orientation ()//Return is "Portrait": Represents the vertical screen, the return is "landscape" means the horizontal screen
(2) $ (window). On (' Orientation:change ', function (e,type) {//Where the type value is portrait or landscape});//trigger when the screen is converted
Zepto Judge mobile phone screen