Zepto Judge mobile phone screen

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.