-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
80 lines (69 loc) · 2.05 KB
/
Copy pathscript.js
File metadata and controls
80 lines (69 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Hamburger Menu Toggle
const hamburger = document.getElementById('hamburger');
const navbar = document.getElementById('navbar');
if (hamburger && navbar) {
hamburger.addEventListener('click', () => {
navbar.classList.toggle('active');
const icon = hamburger.querySelector('i');
if (navbar.classList.contains('active')) {
icon.classList.remove('fa-bars');
icon.classList.add('fa-times');
} else {
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
}
// Smooth Scrolling for Navigation Links
document.querySelectorAll('.navbar a').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault(); // Prevent default jump
const targetId = link.getAttribute('href').substring(1); // Remove #
if (targetId === "") {
// Home - scroll to top
window.scrollTo({
top: 0,
behavior: 'smooth'
});
} else {
const section = document.getElementById(targetId);
if (section) {
section.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
// Close mobile menu after clicking a link
if (navbar.classList.contains('active')) {
navbar.classList.remove('active');
const icon = hamburger.querySelector('i');
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
});
// Logo Click - Scroll to Top (Home)
const logo = document.querySelector('.logo');
if (logo) {
logo.addEventListener('click', (e) => {
e.preventDefault();
window.scrollTo({
top: 0,
behavior: 'smooth'
});
// Close mobile menu if open
if (navbar.classList.contains('active')) {
navbar.classList.remove('active');
const icon = hamburger.querySelector('i');
icon.classList.remove('fa-times');
icon.classList.add('fa-bars');
}
});
}
// Experiment HC
const button = document.getElementById("hello-btn")
button.addEventListener('click', doSomething)
function doSomething(){
alert("Hello, welcome to my website!")
}