7.2 KiB
7.2 KiB
모바일 메뉴가 동작하지 않는 문제를 찾았습니다! 🔍 🔴 문제점 발견
- 클래스명 불일치 (가장 큰 문제!) script.js: javascriptconst menuBtn = document.querySelector('.menu-btn'); // ❌ .menu-btn const navMenu = document.querySelector('.nav-menu'); // ❌ .nav-menu index.html: html
- 닫기 버튼도 작동 안 함 script.js: javascriptdocument.querySelectorAll('.modal .close-btn').forEach(btn => { // ❌ .close-btn 클래스를 찾지만... }); index.html: html×
- 이벤트 핸들러 중복 script.js 하단: javascript// 메뉴 토글 코드가 있는데... const menuBtn = document.querySelector('.menu-btn'); index.html 하단: html
📋 문제 요약 요소script.js에서 찾는 것index.html 실제메뉴 버튼.menu-btn#mobile-menu-btn (클래스 없음)메뉴.nav-menu#mobile-menu (클래스 없음)닫기 버튼.modal .close-btn#close-menu-btn (클래스 없음)
✅ 해결 방법 (3가지 옵션) 옵션 1: script.js 수정 (권장) ID로 찾도록 변경: javascriptconst menuBtn = document.querySelector('#mobile-menu-btn'); // ID로 변경 const navMenu = document.querySelector('#mobile-menu'); // ID로 변경 옵션 2: index.html 수정 클래스 추가: html
옵션 3: 둘 다 수정HTML에 클래스 추가 + script.js도 ID로 변경
🎯 추가 문제점 4. 메뉴 링크 클릭 시 닫기 기능 없음 모바일 메뉴에서 링크 클릭해도 메뉴가 안 닫힙니다: javascript// 이 기능이 script.js에 없음! // 메뉴 내부 링크 클릭 시 메뉴 닫기 5. translate-x-full 제어 없음 html