-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
76 lines (61 loc) · 2.55 KB
/
script.js
File metadata and controls
76 lines (61 loc) · 2.55 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
document.addEventListener("DOMContentLoaded", function () {
const menu = document.querySelector(".dropdown-menu");
const toggleBtn = document.querySelector(".toggle-btn");
const closeBtn = document.querySelector(".close-btn");
const backToTopBtn = document.getElementById("back-to-top");
toggleBtn.addEventListener("click", function () {
menu.classList.toggle("open");
});
closeBtn.addEventListener("click", function () {
menu.classList.remove("open");
});
// Close menu when clicking outside of it
document.addEventListener("click", function (event) {
if (!menu.contains(event.target) && !toggleBtn.contains(event.target)) {
menu.classList.remove("open");
}
});
// Function to handle scroll events
window.onscroll = function() {
scrollFunction();
toggleBackToTopButton(); // Call the function to show/hide the button
};
function scrollFunction() {
const navbar = document.querySelector('.navbar');
const logo = document.querySelector('.logo img');
const header = document.querySelector('.header');
if (document.body.scrollTop > 80 || document.documentElement.scrollTop > 80) {
navbar.style.fontSize = '14px';
logo.style.height = '60px';
header.style.padding = '5px 5%';
header.style.background = '#ec3c20';
} else {
navbar.style.fontSize = '16px';
logo.style.height = '80px';
header.style.padding = '10px 5%';
header.style.background = 'transparent';
}
}
// Function to toggle the visibility of the back-to-top button
function toggleBackToTopButton() {
if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
backToTopBtn.style.display = "block"; // Show the button
} else {
backToTopBtn.style.display = "none"; // Hide the button
}
}
// Scroll to top when the button is clicked
backToTopBtn.addEventListener('click', function() {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
});
document.addEventListener('DOMContentLoaded', function() {
const navLinks = document.querySelectorAll('.navbar a');
const currentPage = window.location.pathname.split('/').pop(); // Get the filename of the current page
navLinks.forEach(link => {
const linkPath = link.getAttribute('href').split('/').pop();
if (linkPath === currentPage) {
link.classList.add('active');
}
});
});