CoolFace
Apppublic

mathurhimika/biotech-horizon-explorer

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
script.js59 linesDownload Raw Back to root
1document.addEventListener('DOMContentLoaded', function() {2    // Back to top button3    const backToTopButton = document.getElementById('backToTop');4    5    window.addEventListener('scroll', function() {6        if (window.pageYOffset > 300) {7            backToTopButton.classList.remove('opacity-0', 'invisible');8            backToTopButton.classList.add('opacity-100', 'visible');9        } else {10            backToTopButton.classList.remove('opacity-100', 'visible');11            backToTopButton.classList.add('opacity-0', 'invisible');12        }13    });14    15    backToTopButton.addEventListener('click', function() {16        window.scrollTo({17            top: 0,18            behavior: 'smooth'19        });20    });21 22    // Add animation classes to elements when they come into view23    const animateOnScroll = function() {24        const elements = document.querySelectorAll('.fade-in');25        26        elements.forEach(element => {27            const elementPosition = element.getBoundingClientRect().top;28            const windowHeight = window.innerHeight;29            30            if (elementPosition < windowHeight - 100) {31                element.classList.add('animate-fadeIn');32            }33        });34    };35    36    window.addEventListener('scroll', animateOnScroll);37    animateOnScroll(); // Trigger on load for elements already in view38    39    // Smooth scroll for anchor links40    document.querySelectorAll('a[href^="#"]').forEach(anchor => {41        anchor.addEventListener('click', function(e) {42            e.preventDefault();43            44            const targetId = this.getAttribute('href');45            if (targetId === '#') return;46            47            const targetElement = document.querySelector(targetId);48            if (targetElement) {49                window.scrollTo({50                    top: targetElement.offsetTop - 80,51                    behavior: 'smooth'52                });53            }54        });55    });56    57    // Feather icons replacement58    feather.replace();59});