MeshTech's picture
I SAID THE APP IS CALLED MYUG, ADD NAVIGATIONS TABS AT THE TOP AND I GIVE YOU PERMISSION TO GO AHEAD AND GENERATE INFO FOR IT. USE IMAGES ALOT THAT COVER THE SPACE AND DISAPPEAR AND DO NICE STUFF THAT TNERTAINS THE VIEWER
761fbc1 verified
Raw History Blame Contribute Delete
4.19 kB
// Initialize service worker for PWA functionality
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js').then(registration => {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(err => {
console.log('ServiceWorker registration failed: ', err);
});
});
}
// Handle location permission request
document.addEventListener('DOMContentLoaded', () => {
const locationBtn = document.getElementById('get-location');
if (locationBtn) {
locationBtn.addEventListener('click', () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
position => {
console.log('Position:', position);
// In a real app, you would send this to your backend
},
error => {
console.error('Error getting location:', error);
alert('Could not get your location. Please enable location services or enter it manually.');
},
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 0 }
);
} else {
alert('Geolocation is not supported by your browser.');
}
});
}
});
// Mock API calls for demo purposes
async function fetchServices() {
try {
// In a real app, this would be a fetch to your backend API
const mockServices = [
{ id: 1, name: 'Towing', icon: 'truck', description: 'Vehicle towing services' },
{ id: 2, name: 'Mechanic', icon: 'tool', description: 'On-site mechanic assistance' },
{ id: 3, name: 'Jump Start', icon: 'battery', description: 'Battery jump start service' },
{ id: 4, name: 'Fuel Delivery', icon: 'droplet', description: 'Emergency fuel delivery' }
];
return mockServices;
} catch (error) {
console.error('Error fetching services:', error);
return [];
}
}
// Parallax effect
function setupParallax() {
const hero = document.querySelector('.hero-section');
if (hero) {
window.addEventListener('scroll', () => {
const scrollPosition = window.pageYOffset;
hero.style.backgroundPositionY = scrollPosition * 0.5 + 'px';
});
}
}
// Animate services on scroll
function animateServices() {
const servicesGrid = document.getElementById('services-grid');
if (servicesGrid) {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
entry.target.style.opacity = 1;
entry.target.style.transform = 'translateY(0)';
}
});
}, { threshold: 0.1 });
const cards = servicesGrid.children;
Array.from(cards).forEach((card, index) => {
card.style.opacity = 0;
card.style.transform = 'translateY(20px)';
card.style.transition = `all 0.5s ease ${index * 0.1}s`;
observer.observe(card);
});
}
}
// Initialize the app
document.addEventListener('DOMContentLoaded', async () => {
console.log('MYUG App initialized');
setupParallax();
animateServices();
initImageSlider();
// Load services
const services = await fetchServices();
console.log('Services loaded:', services);
// Add futuristic hover effects to all cards
document.querySelectorAll('.service-card').forEach(card => {
card.classList.add('futuristic-card');
});
});
function initImageSlider() {
const sliders = document.querySelectorAll('.image-slider');
sliders.forEach((slider, index) => {
const images = slider.querySelectorAll('img');
let current = 0;
setInterval(() => {
images[current].style.opacity = 0;
current = (current + 1) % images.length;
images[current].style.opacity = 1;
}, 5000);
});
}