pc, 모바일(노터치, 터치) 구분 스크립트

2023. 8. 16. 12:33javaScript

// pc, 모바일 구분
const isMobile = () => {
  const user = navigator.userAgent;
  let isCheck = 'PC';

  if ( user.indexOf("iPhone") > -1 || user.indexOf("Android") > -1 ) {
      isCheck = 'MO';
  }

  return isCheck;
}

$(window).resize(function (){
  mainNavSize();
});

function mainNavSize() {
  if(isMobile() == 'PC') {
    var windowWidth = $(window).width(); //요소의 너비를 반환
    // 768
    if(windowWidth < 769) {
      // 모바일
      $('main nav ul').css("width", "100%");
      $('main nav ul a').css("font-size", "10px");
    } else {
      // pc
      $('main nav ul').css("width", "");
      $('main nav ul a').css("font-size", "");
    }
  }
}