-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
82 lines (65 loc) · 2.42 KB
/
app.js
File metadata and controls
82 lines (65 loc) · 2.42 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
81
82
// Carousel functionality
document.addEventListener("DOMContentLoaded", function () {
const track = document.querySelector(".carousel-track");
const cards = document.querySelectorAll(".product-card");
const prevBtn = document.querySelector(".carousel-btn.prev");
const nextBtn = document.querySelector(".carousel-btn.next");
if (!track || !cards.length) return;
let currentIndex = 0;
const cardWidth = cards[0].offsetWidth + 30; // width + gap
function updateCarousel() {
track.style.transform = `translateX(-${currentIndex * cardWidth}px)`;
}
nextBtn.addEventListener("click", function () {
if (currentIndex < cards.length - 3) {
currentIndex++;
updateCarousel();
}
});
prevBtn.addEventListener("click", function () {
if (currentIndex > 0) {
currentIndex--;
updateCarousel();
}
});
// Handle window resize
window.addEventListener("resize", function () {
cardWidth = cards[0].offsetWidth + 30;
updateCarousel();
});
});
// Burger menu functionality
document.addEventListener('DOMContentLoaded', function() {
const burgerMenu = document.querySelector('.burger-menu');
const navWrapper = document.querySelector('.nav-wrapper');
if (!burgerMenu || !navWrapper) return;
burgerMenu.addEventListener('click', function() {
// Toggle active class on burger menu
this.classList.toggle('active');
// Toggle active class on navigation wrapper
navWrapper.classList.toggle('active');
// Prevent body scrolling when menu is open
document.body.style.overflow = navWrapper.classList.contains('active') ? 'hidden' : '';
});
// Close menu when clicking on a link
const navLinks = document.querySelectorAll('.nav-wrapper a');
navLinks.forEach(link => {
link.addEventListener('click', function() {
burgerMenu.classList.remove('active');
navWrapper.classList.remove('active');
document.body.style.overflow = '';
});
});
// Close menu when clicking outside on mobile
document.addEventListener('click', function(event) {
if (window.innerWidth <= 768 &&
!navWrapper.contains(event.target) &&
!burgerMenu.contains(event.target) &&
navWrapper.classList.contains('active')) {
burgerMenu.classList.remove('active');
navWrapper.classList.remove('active');
document.body.style.overflow = '';
}
});
});
// this is made by ai, not me, i dont know that much js :)