Spaces:
Running
Running
File size: 9,508 Bytes
389ae80 |
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
// Initialize everything when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
// Initialize mobile menu
initMobileMenu();
// Initialize smooth scrolling
initSmoothScroll();
// Initialize form handling
initSignupForm();
// Initialize scroll animations
initScrollAnimations();
// Initialize parallax effects
initParallaxEffects();
});
// Mobile menu functionality
function initMobileMenu() {
const mobileMenuBtn = document.getElementById('mobileMenuBtn');
const nav = document.querySelector('nav');
if (mobileMenuBtn) {
mobileMenuBtn.addEventListener('click', function() {
// Toggle mobile menu
const mobileMenu = document.createElement('div');
mobileMenu.className = 'fixed inset-0 bg-white z-40 mobile-menu-enter';
mobileMenu.innerHTML = `
<div class="p-6">
<div class="flex justify-between items-center mb-8">
<span class="text-2xl font-bold text-gradient">StartupLaunch Pro</span>
<button id="closeMobileMenu" class="p-2">
<i data-feather="x"></i>
</button>
</div>
<div class="flex flex-col space-y-4">
<a href="#features" class="text-lg text-gray-700 hover:text-purple-600 transition">Features</a>
<a href="#solution" class="text-lg text-gray-700 hover:text-purple-600 transition">Solution</a>
<a href="#team" class="text-lg text-gray-700 hover:text-purple-600 transition">Team</a>
<a href="#press" class="text-lg text-gray-700 hover:text-purple-600 transition">Press</a>
<button class="bg-gradient-to-r from-purple-600 to-indigo-600 text-white px-6 py-3 rounded-full hover:shadow-lg transition mt-4">
Get Started
</button>
</div>
</div>
`;
document.body.appendChild(mobileMenu);
feather.replace();
// Close menu functionality
document.getElementById('closeMobileMenu').addEventListener('click', function() {
mobileMenu.remove();
});
// Close on link click
mobileMenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', function() {
mobileMenu.remove();
});
});
});
}
}
// Smooth scrolling for anchor links
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const offset = 80; // Account for fixed header
const targetPosition = target.offsetTop - offset;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
}
// Email signup form handling
function initSignupForm() {
const signupForm = document.getElementById('signupForm');
const emailInput = document.getElementById('emailInput');
const successMessage = document.getElementById('successMessage');
if (signupForm) {
signupForm.addEventListener('submit', function(e) {
e.preventDefault();
const email = emailInput.value;
// Validate email
if (!validateEmail(email)) {
showError('Please enter a valid email address');
return;
}
// Simulate API call
const button = signupForm.querySelector('button[type="submit"]');
const originalText = button.textContent;
button.textContent = 'Sending...';
button.disabled = true;
setTimeout(() => {
// Show success message
successMessage.classList.remove('hidden');
emailInput.value = '';
button.textContent = originalText;
button.disabled = false;
// Hide success message after 5 seconds
setTimeout(() => {
successMessage.classList.add('hidden');
}, 5000);
// Store email (in real app, this would be sent to backend)
console.log('Email signed up:', email);
}, 1500);
});
}
}
// Email validation helper
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
// Show error message
function showError(message) {
const errorDiv = document.createElement('div');
errorDiv.className = 'fixed top-20 right-6 bg-red-500 text-white px-6 py-3 rounded-lg shadow-lg z-50';
errorDiv.textContent = message;
document.body.appendChild(errorDiv);
setTimeout(() => {
errorDiv.remove();
}, 3000);
}
// Scroll animations
function initScrollAnimations() {
// Add animation to elements when they come into view
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe elements with animation
document.querySelectorAll('[data-aos]').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'all 0.6s ease-out';
observer.observe(el);
});
}
// Parallax effects
function initParallaxEffects() {
let ticking = false;
function updateParallax() {
const scrolled = window.pageYOffset;
const parallaxElements = document.querySelectorAll('.float-animation');
parallaxElements.forEach(el => {
const speed = 0.5;
const yPos = -(scrolled * speed);
el.style.transform = `translateY(${yPos}px)`;
});
ticking = false;
}
function requestTick() {
if (!ticking) {
window.requestAnimationFrame(updateParallax);
ticking = true;
}
}
window.addEventListener('scroll', requestTick);
}
// Add number counter animation
function animateCounter(element, target, duration = 2000) {
let start = 0;
const increment = target / (duration / 16);
const timer = setInterval(() => {
start += increment;
if (start >= target) {
element.textContent = target.toLocaleString();
clearInterval(timer);
} else {
element.textContent = Math.floor(start).toLocaleString();
}
}, 16);
}
// Lazy load images
function lazyLoadImages() {
const images = document.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy-image');
img.classList.add('loaded');
imageObserver.unobserve(img);
}
});
});
images.forEach(img => {
img.classList.add('lazy-image');
imageObserver.observe(img);
});
}
// Add hover effect to cards
document.querySelectorAll('.hover-lift').forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-10px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Add typing effect to hero text
function typeWriter(element, text, speed = 50) {
let i = 0;
element.textContent = '';
function type() {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Initialize on scroll progress bar
function initScrollProgress() {
const progressBar = document.createElement('div');
progressBar.className = 'fixed top-0 left-0 w-full h-1 bg-gradient-to-r from-purple-600 to-indigo-600 z-50 transform origin-left';
progressBar.style.transform = 'scaleX(0)';
progressBar.style.transition = 'transform 0.1s';
document.body.appendChild(progressBar);
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const maxScroll = document.documentElement.scrollHeight - window.innerHeight;
const progress = scrolled / maxScroll;
progressBar.style.transform = `scaleX(${progress})`;
});
}
// Initialize all features
window.addEventListener('load', () => {
lazyLoadImages();
initScrollProgress();
// Add loading animation removal
document.body.classList.add('loaded');
}); |