CoolFace
Apppublic

acs-dev/codecrafted-ios-portfolio

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
script.js37 linesDownload Raw Back to root
1document.addEventListener('DOMContentLoaded', function() {2    // Theme toggle functionality3    const themeToggle = document.createElement('div');4    themeToggle.className = 'fixed bottom-6 right-6 z-50';5    themeToggle.innerHTML = `6        <button id="themeToggle" class="p-3 rounded-full bg-white dark:bg-gray-800 shadow-lg hover:shadow-xl transition-all">7            <i data-feather="moon" class="hidden dark:block text-yellow-400"></i>8            <i data-feather="sun" class="dark:hidden text-gray-700"></i>9        </button>10    `;11    document.body.appendChild(themeToggle);12    13    document.getElementById('themeToggle').addEventListener('click', function() {14        document.documentElement.classList.toggle('dark');15        localStorage.setItem('darkMode', document.documentElement.classList.contains('dark'));16        feather.replace();17    });18    19    // Check for saved theme preference20    if (localStorage.getItem('darkMode') === 'true') {21        document.documentElement.classList.add('dark');22    } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {23        document.documentElement.classList.add('dark');24    }25    26    feather.replace();27    28    // Smooth scrolling for anchor links29    document.querySelectorAll('a[href^="#"]').forEach(anchor => {30        anchor.addEventListener('click', function (e) {31            e.preventDefault();32            document.querySelector(this.getAttribute('href')).scrollIntoView({33                behavior: 'smooth'34            });35        });36    });37});