简体   繁体   中英

How do I correct this syntax to detect ipad browser orientation

I am trying to enable/disable plugins based on iPad orientation.

I started with this: https://jsfiddle.net/4hnr2ef8/

I then found this article recommendeding this method and I now have this, but is the syntax correct? I keep closing areas that seem open but no luck: https://jsfiddle.net/am86cqto/

function readDeviceOrientation() {
switch (window.orientation) {  
case 0:  

    // Portrait 
    break; 
    $(function() {
        $.scrollify({
            section : ".scrollify",
            sectionName: "section-name",
            easing: "easeInOutCubic",
            scrollSpeed: 1100
        });
    var s = skrollr.init({
        forceHeight: false
    });

case 180:  

    // Portrait (Upside-down)
    break; 
    $(function() {
        $.scrollify({
            section : ".scrollify",
            sectionName: "section-name",
            easing: "easeInOutCubic",
            scrollSpeed: 1100
        });
    var s = skrollr.init({
        forceHeight: false
    });

case -90:  

    // Landscape (Clockwise)
    break;
    if ($(window).width() < 768) {
        $.scrollify.disable()
    }
    else {
        $.scrollify.enable()
    }  

case 90:  

    // Landscape  (Counterclockwise)
    break;
    if ($(window).width() < 768) {
        $.scrollify.disable()
    }
    else {
        $.scrollify.enable()
    }
}

}

Thanks, Kevin W.

You have to use this way until browsers support window.screen.orientation

function getScreenOrientation(){
 return screen.width > screen.height ? "landscape" : "portrait";
}

To detect orientation only on mobiles and tablets

function getScreenOrientation(){
    if (/Mobi/.test(navigator.userAgent)) {
        return screen.width > screen.height ? "landscape" : "portrait";
    }
    return "landscape";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM