반응형

모바일 가로화면 감지

orientationchange 사용

 


window.addEventListener("orientationchange", function() {

if(window.orientation == -90 || window.orientation == 90) {
//가로화면일 때
} else {
//세로화면일 때
}

}, false);


window.orientation 값이 0일 경우는 세로화면이고

90일 경우와 -90일 경우가

각각 오른쪽 가로화면, 왼쪽 가로화면 입니다.

 

if 문 안에 가로화면일 때 원하는 코드를 넣으면 됩니다.

 

초기 실행시 orientation 감지


document.addEventListener("DOMContentLoaded", function(){

if(window.orientation == -90 || window.orientation == 90) {
//가로 화면일 경우 처리 코드
}

});

 

[출처] [javascript] 모바일 가로 화면 감지 (하드코딩하는사람들) | 작성자 JYL

728x90
반응형

'web > javascript & jquery' 카테고리의 다른 글

default parameter value 파라메터 기본값  (0) 2021.03.22
[펌]글자 타이핑 효과  (0) 2020.08.26
video tag  (0) 2020.06.04
html 에 수학 수식을 사용해보자  (0) 2020.05.18
슬라이딩 메뉴 , 드롭다운메뉴  (0) 2019.12.24

+ Recent posts