HerzaJ commited on
Commit
df5ac96
·
verified ·
1 Parent(s): 3435e7d

Update public/index.js

Browse files
Files changed (1) hide show
  1. public/index.js +22 -5
public/index.js CHANGED
@@ -229,21 +229,38 @@ if (navMenu) {
229
 
230
  document.querySelectorAll('.nav-link').forEach(link => {
231
  link.addEventListener('click', (e) => {
232
- if (!link.getAttribute('href').startsWith('#')) {
 
233
  closeMenu();
 
 
 
 
 
 
 
 
 
234
  }
235
  });
236
  });
237
 
238
  document.querySelectorAll('a[href^="#"]').forEach(anchor => {
239
  anchor.addEventListener('click', function (e) {
 
 
 
240
  e.preventDefault();
241
- const target = document.querySelector(this.getAttribute('href'));
242
  if (target) {
243
- closeMenu();
244
- setTimeout(() => {
 
 
 
 
245
  target.scrollIntoView({ behavior: 'smooth', block: 'start' });
246
- }, 400);
247
  }
248
  });
249
  });
 
229
 
230
  document.querySelectorAll('.nav-link').forEach(link => {
231
  link.addEventListener('click', (e) => {
232
+ const href = link.getAttribute('href');
233
+ if (href && !href.startsWith('#')) {
234
  closeMenu();
235
+ } else if (href && href.startsWith('#')) {
236
+ e.preventDefault();
237
+ const target = document.querySelector(href);
238
+ if (target) {
239
+ closeMenu();
240
+ setTimeout(() => {
241
+ target.scrollIntoView({ behavior: 'smooth', block: 'start' });
242
+ }, 400);
243
+ }
244
  }
245
  });
246
  });
247
 
248
  document.querySelectorAll('a[href^="#"]').forEach(anchor => {
249
  anchor.addEventListener('click', function (e) {
250
+ const href = this.getAttribute('href');
251
+ if (!href || href === '#') return;
252
+
253
  e.preventDefault();
254
+ const target = document.querySelector(href);
255
  if (target) {
256
+ if (navMenu && navMenu.classList.contains('active')) {
257
+ closeMenu();
258
+ setTimeout(() => {
259
+ target.scrollIntoView({ behavior: 'smooth', block: 'start' });
260
+ }, 400);
261
+ } else {
262
  target.scrollIntoView({ behavior: 'smooth', block: 'start' });
263
+ }
264
  }
265
  });
266
  });