[CSS] PC와 Mobile을 구분하는 2가지 방법
😊 이번 시간에는 css를 사용해 pc와 mobile을 구분하는 방법에 대해 알아보았다! 1. ontouchstart로 구분하기 1) touchstart 이벤트? touchstart 이벤트는 터치가 가능한 디바이스에서만 발생한다. 만약 터치가 불가한 환경(ex. pc)인 경우 ontouchstart값은 undefined가 된다. window.ontouchstart; 2) 사용법 💡 CSS에서 PC, Mobile별로 다른 스타일을 주고 싶다면, 아래 방법을 써보자! (1) ontouchstart여부를 dataset에 저장해준다. // js function checkTouchable() { document.body.dataset.touchable = !!window.ontouchstart; } checkTo..
2022. 6. 15.