JavaScript algorithm to determine orientation of tablet

前端 未结 1 1742
温柔的废话
温柔的废话 2021-01-05 03:20

We\'re building an HTML5/JavaScript app developed for tablets, and we want to lay out my screens differently in landscape versus portrait.

Originally, we were capt

1条回答
  •  执念已碎
    2021-01-05 04:02

    http://jsfiddle.net/jjc39/

    Try this:

    orientation​
    
    $(document).ready(checkOrientation);
    $(window).resize(checkOrientation);
    
    function checkOrientation() {
        var orientation = "Portrait";
        var screenWidth = $(window).width();
        var screenHeight = $(window).height();
        if (screenWidth > screenHeight) {
            orientation = "Landscape";
        }
        $("#orientation").html(orientation);
    }​
    

    0 讨论(0)
提交回复
热议问题