RotBench / assets /js /script.js
akhaliq's picture
akhaliq HF Staff
Upload folder using huggingface_hub
f9b8369 verified
Raw
History Blame Contribute Delete
3.73 kB
// Smooth scrolling for navigation links
document.addEventListener('DOMContentLoaded', function() {
// Smooth scrolling
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
const offsetTop = targetSection.offsetTop - 60; // Adjust for fixed header
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
// Close mobile menu if open
const navMenu = document.querySelector('.nav-menu');
const hamburger = document.querySelector('.hamburger');
navMenu.classList.remove('active');
hamburger.classList.remove('active');
}
});
});
// Mobile menu toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', function() {
navMenu.classList.toggle('active');
this.classList.toggle('active');
});
// Close mobile menu when clicking outside
document.addEventListener('click', function(e) {
if (!hamburger.contains(e.target) && !navMenu.contains(e.target)) {
navMenu.classList.remove('active');
hamburger.classList.remove('active');
}
});
// Sticky navbar effect
const navbar = document.querySelector('.navbar');
let lastScrollY = window.scrollY;
window.addEventListener('scroll', function() {
if (window.scrollY > 100) {
navbar.style.background = 'rgba(255, 255, 255, 0.95)';
} else {
navbar.style.background = 'rgba(255, 255, 255, 0.8)';
}
// Hide navbar on scroll down, show on scroll up
if (window.scrollY > lastScrollY && window.scrollY > 200) {
navbar.style.transform = 'translateY(-100%)';
} else {
navbar.style.transform = 'translateY(0)';
}
lastScrollY = window.scrollY;
});
// Lazy loading for images
const lazyImages = document.querySelectorAll('img[loading="lazy"]');
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.src;
imageObserver.unobserve(img);
}
});
});
lazyImages.forEach(img => imageObserver.observe(img));
}
// Add subtle animations on scroll
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 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 sections for animation
const sections = document.querySelectorAll('.section');
sections.forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(section);
});
});