-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
197 lines (170 loc) · 5.97 KB
/
index.js
File metadata and controls
197 lines (170 loc) · 5.97 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Navbar scroll effect
let lastScroll = 0;
const navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
navbar.style.background = 'rgba(15, 23, 42, 0.95)';
navbar.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.3)';
} else {
navbar.style.background = 'rgba(15, 23, 42, 0.9)';
navbar.style.boxShadow = 'none';
}
lastScroll = currentScroll;
});
// Intersection Observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe all feature cards and step items
document.querySelectorAll('.feature-card, .step-item, .use-case-card').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
// Add parallax effect to floating icons
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const icons = document.querySelectorAll('.floating-icon');
icons.forEach((icon, index) => {
const speed = 0.5 + (index * 0.1);
icon.style.transform = `translateY(${scrolled * speed}px) rotate(${scrolled * 0.1}deg)`;
});
});
// Add hover effect to buttons
document.querySelectorAll('.btn').forEach(btn => {
btn.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-3px) scale(1.05)';
});
btn.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Animate stats on scroll
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const statNumber = entry.target.querySelector('.stat-number');
if (statNumber && !statNumber.classList.contains('animated')) {
statNumber.classList.add('animated');
animateValue(statNumber, 0, 100, 2000);
}
}
});
}, { threshold: 0.5 });
const statItems = document.querySelectorAll('.stat-item');
statItems.forEach(item => {
statsObserver.observe(item);
});
function animateValue(element, start, end, duration) {
if (element.textContent.includes('%')) {
let startTime = null;
const animate = (currentTime) => {
if (startTime === null) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const progress = Math.min(timeElapsed / duration, 1);
const current = Math.floor(progress * (end - start) + start);
element.textContent = current + '%';
if (progress < 1) {
requestAnimationFrame(animate);
}
};
requestAnimationFrame(animate);
}
}
// Add random rotation to floating icons on hover
document.querySelectorAll('.floating-icon').forEach(icon => {
icon.addEventListener('mouseenter', function() {
this.style.animation = 'none';
this.style.transform = `rotate(${Math.random() * 360}deg) scale(1.5)`;
this.style.opacity = '0.3';
});
icon.addEventListener('mouseleave', function() {
this.style.animation = '';
this.style.transform = '';
this.style.opacity = '0.1';
});
});
// Add typing effect to hero subtitle (optional enhancement)
const heroSubtitle = document.querySelector('.hero-subtitle');
if (heroSubtitle) {
const text = heroSubtitle.textContent;
heroSubtitle.textContent = '';
let index = 0;
function typeText() {
if (index < text.length) {
heroSubtitle.textContent += text.charAt(index);
index++;
setTimeout(typeText, 30);
}
}
// Start typing after a short delay
setTimeout(typeText, 500);
}
// Add ripple effect to buttons
document.querySelectorAll('.btn').forEach(btn => {
btn.addEventListener('click', function(e) {
const ripple = document.createElement('span');
const rect = this.getBoundingClientRect();
const size = Math.max(rect.width, rect.height);
const x = e.clientX - rect.left - size / 2;
const y = e.clientY - rect.top - size / 2;
ripple.style.width = ripple.style.height = size + 'px';
ripple.style.left = x + 'px';
ripple.style.top = y + 'px';
ripple.classList.add('ripple');
this.appendChild(ripple);
setTimeout(() => {
ripple.remove();
}, 600);
});
});
// Add CSS for ripple effect
const style = document.createElement('style');
style.textContent = `
.btn {
position: relative;
overflow: hidden;
}
.ripple {
position: absolute;
border-radius: 50%;
background: rgba(255, 255, 255, 0.6);
transform: scale(0);
animation: ripple-animation 0.6s ease-out;
pointer-events: none;
}
@keyframes ripple-animation {
to {
transform: scale(4);
opacity: 0;
}
}
`;
document.head.appendChild(style);
// Console easter egg
console.log('%c🧬 Dietary Deep Scan System', 'font-size: 20px; font-weight: bold; color: #4ade80;');
console.log('%cMaking food safety accessible to everyone!', 'font-size: 12px; color: #4ade80;');