forked from InnerveSummerOfCode/ISOC-23-WEBD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisoc.js
82 lines (68 loc) · 2.28 KB
/
isoc.js
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
81
82
// sticky navbar
window.onscroll = function() {myFunction()};
// Get the navbar
var navbar = document.getElementById("navbar");
// Get the offset position of the navbar
var sticky = navbar.offsetTop;
// Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
// function to Toggle Light and Dark Mode
var icon = document.getElementById("icon");
icon.onclick = function(){
document.body.classList.toggle("dark-theme");
if(document.body.classList.contains("dark-theme")){
icon.src = "Our Gallery/sun (1).png";
}
else{
icon.src = "Our Gallery/moon.png";
}
}
let navbarMenu = document.querySelector('.navbar-menu');
let dropdownIsOpen = false;
// Handle dropdown menu toggle
navbarMenu.addEventListener('click', (event) => {
if (event.target.classList.contains('dropdown-toggler')) {
let target = document.querySelector(`#${event.target.dataset.dropdown}`);
if (target) {
if (target.classList.contains('show')) {
target.classList.remove('show');
dropdownIsOpen = false;
} else {
target.classList.add('show');
dropdownIsOpen = true;
}
}
}
});
// Handle closing dropdowns if a user clicks outside
document.body.addEventListener('click', (event) => {
if (dropdownIsOpen) {
navbarMenu.querySelectorAll('.dropdown').forEach((dropdown) => {
let targetIsDropdown = dropdown == event.target;
let clickedOnDropdownToggle = event.target.classList.contains('dropdown-toggler');
if (clickedOnDropdownToggle) {
return;
}
if (!targetIsDropdown && !dropdown.contains(event.target)) {
dropdown.classList.remove('show');
}
});
}
});
// Open links in mobiles
function handleSmallScreens() {
document.querySelector('.navbar-toggler').addEventListener('click', () => {
if (!navbarMenu.classList.contains('active')) {
navbarMenu.classList.add('active');
} else {
navbarMenu.classList.remove('active');
}
});
}
handleSmallScreens();