-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (63 loc) · 2.51 KB
/
index.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
document.addEventListener('DOMContentLoaded', () => {
// Hamburger menu toggle
const hamburger = document.querySelector('.hamburger');
const navbar = document.querySelector('.navbar');
hamburger.addEventListener('click', () => {
navbar.classList.toggle('active');
});
// Smooth scrolling
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Countdown timer
function countdown() {
const endDate = new Date("Dec 31, 2024 23:59:59").getTime();
const now = new Date().getTime();
const timeLeft = endDate - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
document.querySelector('.discount-news .time').innerHTML =
`<label>${days}<span>:</span></label>
<label>${hours}<span>:</span></label>
<label>${minutes}<span>:</span></label>
<label>${seconds}</label>`;
if (timeLeft < 0) {
clearInterval(timerInterval);
document.querySelector('.discount-news .time').innerHTML = "EXPIRED";
}
}
const timerInterval = setInterval(countdown, 1000);
countdown();
// Intersection Observer for animations
const observerOptions = {
root: null,
rootMargin: "0px",
threshold: 0.1
};
const observerCallback = (entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('in-view');
observer.unobserve(entry.target);
}
});
};
const observer = new IntersectionObserver(observerCallback, observerOptions);
document.querySelectorAll('.category, .most-rated, .popular-products, .discount-news, .our-services').forEach(section => {
observer.observe(section);
});
// Add 'in-view' class for the CSS to handle animations
const styleSheet = document.styleSheets[0];
styleSheet.insertRule(`
.in-view {
animation: fadeIn 1s ease-in-out;
}
`, styleSheet.cssRules.length);
});