Morioun's picture
Нет, переделай весь сайт под Duolingo
adbed4a verified
Raw History Blame Contribute Delete
1.88 kB
// Duolingo-style animations
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
target.style.transform = 'translateY(-5px)';
setTimeout(() => {
target.style.transform = 'translateY(0)';
}, 300);
target.scrollIntoView({
behavior: 'smooth'
});
});
});
// Duolingo-style scroll animations
const animateOnScroll = () => {
const elements = document.querySelectorAll('.feature-card, .step, .hero-content');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.animation = 'duoSlideUp 0.6s ease forwards';
observer.unobserve(entry.target);
}
});
}, { threshold: 0.1 });
elements.forEach(element => {
element.style.opacity = '0';
element.style.transform = 'translateY(20px)';
observer.observe(element);
});
};
// Add Duolingo-style animation
const style = document.createElement('style');
style.textContent = `
@keyframes duoSlideUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
`;
document.head.appendChild(style);
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
animateOnScroll();
// Mobile menu toggle
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
if (mobileMenuBtn) {
mobileMenuBtn.addEventListener('click', () => {
const navLinks = document.querySelector('.nav-links');
navLinks.style.display = navLinks.style.display === 'flex' ? 'none' : 'flex';
});
}
});