如何更正此语法以检测ipad浏览器方向

时间:2021-12-13 07:16:50

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

我正在尝试根据iPad方向启用/禁用插件。

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

我从这开始: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/

然后我发现这篇文章推荐了这个方法,我现在有了这个,但语法是否正确?我一直关闭看似开放但没有运气的区域: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.

谢谢,凯文W.

1 个解决方案

#1


0  

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

您必须使用这种方式,直到浏览器支持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";
}

#1


0  

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

您必须使用这种方式,直到浏览器支持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";
}