-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindexmain.js
76 lines (64 loc) · 2.76 KB
/
indexmain.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
// Function to handle when the LogIn button is clicked
function toggleLogIn() {
var login = document.getElementById('js_login');
var signup = document.getElementById('js_signup');
// Check and change display status
if (login.style.display === 'flex') {
login.style.display = 'none'; // Hide LogIn if it’s currently displayed
} else {
login.style.display = 'flex'; // Display LogIn
signup.style.display = 'none'; // Hide SignUp if it’s currently displayed
}
}
// Function to handle when the SignUp button is clicked
function toggleSignUp() {
var login = document.getElementById('js_login');
var signup = document.getElementById('js_signup');
// Check and change display status
if (signup.style.display === 'flex') {
signup.style.display = 'none'; // Hide SignUp if it’s currently displayed
} else {
signup.style.display = 'flex'; // Display SignUp
login.style.display = 'none'; // Hide LogIn if it’s currently displayed
}
}
function toggleMenu() {
const dropdownMenu = document.getElementById("dropdown-menu");
dropdownMenu.classList.toggle("show");
}
// Optional: Close the dropdown if a link inside it is clicked
document.querySelectorAll('#dropdown-menu a').forEach(link => {
link.addEventListener('click', () => {
const dropdownMenu = document.getElementById("dropdown-menu");
dropdownMenu.classList.remove("show");
});
});
// Theme toggle functionality
const toggleButton = document.getElementById('theme-toggle');
const body = document.body;
toggleButton.addEventListener('click', () => {
body.classList.toggle('dark-theme');
toggleButton.textContent = body.classList.contains('dark-theme') ? '🌜' : '🌞';
});
//Add a js script with a function that changes the color of the nav-bar each time we find a new color
window.addEventListener('scroll' , function(){
const headerNav = document.querySelector('.header-nav');
if(window.scrollY > 0){
headerNav.classList.add('scrolled');
}else{
headerNav.classList.remove('scrolled');
}
});
//This script controls the dynamic behavior of the nav links underline styling.
//Get all nav links
const navLinks = document.querySelectorAll('.nav li a');
//Adding click event listener to each link
navLinks.forEach(link => {
link.addEventListener('click', function(event){
//event.preventDefault();
//Removing 'active' class from all links
navLinks.forEach(link => link.classList.remove('active'));
//Adding 'active' class only to the clicked link as being active
this.classList.add('active');
});
});