File manager - Edit - /home/webapp69.cm.in.th/u69319090006/portfolio/script.js
Back
// Mobile Menu Toggle const hamburger = document.getElementById('hamburger'); const navMenu = document.getElementById('nav-menu'); const navLinks = document.querySelectorAll('.nav-link, .bottom-nav-link'); // เช็คความปลอดภัยของ element ก่อนรันโค้ดเมนูโมบายล์ if (hamburger && navMenu) { hamburger.addEventListener('click', () => { hamburger.classList.toggle('active'); navMenu.classList.toggle('active'); }); } let isScrollingFromClick = false; let scrollTimeout; // จัดการสถานะการคลิกลิงก์เมนูต่าง ๆ navLinks.forEach(link => { link.addEventListener('click', () => { if (hamburger && navMenu) { hamburger.classList.remove('active'); navMenu.classList.remove('active'); } const targetHref = link.getAttribute('href'); navLinks.forEach(l => { if (l.getAttribute('href') === targetHref) { l.classList.add('active'); } else { l.classList.remove('active'); } }); isScrollingFromClick = true; clearTimeout(scrollTimeout); scrollTimeout = setTimeout(() => { isScrollingFromClick = false; }, 800); }); }); // ระบบสลับโหมด Dark / Light Theme และจดจำสถานะลงบนเบราว์เซอร์ document.addEventListener('DOMContentLoaded', () => { const themeToggle = document.getElementById('theme-toggle'); if (themeToggle) { const savedTheme = localStorage.getItem('theme'); if (savedTheme === 'light') { document.body.classList.add('light-theme'); } themeToggle.addEventListener('click', () => { document.body.classList.toggle('light-theme'); const isLight = document.body.classList.contains('light-theme'); localStorage.setItem('theme', isLight ? 'light' : 'dark'); }); } }); // ตรวจจับการ Scroll ของหน้าจอเพื่อไฮไลท์เมนูปัจจุบัน (Scrollspy) window.addEventListener('scroll', () => { const header = document.querySelector('.header'); if (header) { if (window.scrollY > 50) { header.style.boxShadow = '0 4px 20px rgba(0,0,0,0.3)'; } else { header.style.boxShadow = 'none'; } } if (isScrollingFromClick) return; let currentSection = ''; const sections = document.querySelectorAll('section'); const isBottom = window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 60; if (isBottom) { currentSection = 'contact'; } else { sections.forEach(section => { const sectionTop = section.offsetTop; if (window.scrollY >= sectionTop - 150) { currentSection = section.getAttribute('id'); } }); } navLinks.forEach(link => { link.classList.remove('active'); if (link.getAttribute('href') === `#${currentSection}`) { link.classList.add('active'); } }); }); // สั่งให้ทำงานทันทีหลังโหลดเพื่อคำนวณตำแหน่งเริ่มต้น หน้าแรก window.dispatchEvent(new Event('scroll'));
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.34 |
proxy
|
phpinfo
|
Settings