-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
64 lines (54 loc) · 2.05 KB
/
script.js
File metadata and controls
64 lines (54 loc) · 2.05 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
// script.js
document.addEventListener('DOMContentLoaded', (event) => {
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Handle dropdown menus
const dropdowns = document.querySelectorAll('.dropdown');
dropdowns.forEach(dropdown => {
dropdown.addEventListener('mouseenter', () => {
dropdown.querySelector('.dropdown-content').style.display = 'block';
});
dropdown.addEventListener('mouseleave', () => {
dropdown.querySelector('.dropdown-content').style.display = 'none';
});
});
// Simple responsive menu toggle
const navToggle = document.createElement('button');
navToggle.textContent = 'Menu';
navToggle.classList.add('nav-toggle');
document.querySelector('header .container').prepend(navToggle);
navToggle.addEventListener('click', () => {
document.querySelector('nav').classList.toggle('show');
});
// Header scroll effect
const header = document.querySelector('header');
let lastScrollTop = 0;
window.addEventListener('scroll', () => {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (scrollTop > lastScrollTop) {
header.style.top = '-80px';
} else {
header.style.top = '0';
}
lastScrollTop = scrollTop;
});
// Add animation class to products when they come into view
const products = document.querySelectorAll('.product');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate');
}
});
}, { threshold: 0.1 });
products.forEach(product => {
observer.observe(product);
});
});