본문 바로가기
script

화면회전 in javascript

by [김경민]™ ┌(  ̄∇ ̄)┘™ 2014. 4. 15.
728x90


[출처] http://blog.naver.com/PostView.nhn?blogId=hanoora&logNo=110177880101&redirect=Dlog&widgetTypeCall=true


<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>

 

    <script type="text/javascript">

 

        jQuery("document").ready(function() {

            jQuery(window).trigger("orientationchange"); // 최초 페이지 로딩 시 가로, 세로를 모르기 때문에 trigger로 처리

        });

 

        jQuery(window).bind("orientationchange", function(e) { // 가로세로 전환 처리

            var orientation = window.orientation;

 

            if (orientation == 90 || orientation == -90) {

                alert("portrait");

            } else {

                alert("landscape");

            }

 

        });

 

        jQuery(window).bind("resize", function()) { // 화면 리사이즈 처리

            // 이 경우의 처리는 대부분 가로냐 세로냐의 판단보다는 화면 폭 등을 가져와서 처리하는 경우가 많다.

            var i_tw = document.body.clientWidth;

            

            // 아니면 특정 element 의 폭이나 높이를 가져와야 하는 경우도 있다.

            var i_tw = jQuery("#item1").css("width");

            var i_th = jQuery("#item1").css("height");

        });

 

    </script>


728x90

댓글