yahya3233/audacity-sound-wizardry-tutorial
0
1document.addEventListener('DOMContentLoaded', function() {2 // Smooth scrolling for anchor links3 document.querySelectorAll('a[href^="#"]').forEach(anchor => {4 anchor.addEventListener('click', function (e) {5 e.preventDefault();6 7 const targetId = this.getAttribute('href');8 if (targetId === '#') return;9 10 const targetElement = document.querySelector(targetId);11 if (targetElement) {12 window.scrollTo({13 top: targetElement.offsetTop - 80,14 behavior: 'smooth'15 });16 17 // Update URL without page reload18 history.pushState(null, null, targetId);19 }20 });21 });22 23 // Highlight current section in sidebar24 function highlightCurrentSection() {25 const sections = document.querySelectorAll('section[id]');26 const scrollPosition = window.scrollY + 100;27 28 sections.forEach(section => {29 const sectionTop = section.offsetTop;30 const sectionHeight = section.offsetHeight;31 32 if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {33 const id = section.getAttribute('id');34 const sidebarLink = document.querySelector(`.sidebar-nav a[href="#${id}"]`);35 36 if (sidebarLink) {37 document.querySelectorAll('.sidebar-nav a').forEach(link => {38 link.classList.remove('active');39 });40 sidebarLink.classList.add('active');41 }42 }43 });44 }45 46 window.addEventListener('scroll', highlightCurrentSection);47 highlightCurrentSection(); // Run once on page load48 49 // Back to top button50 const backToTopButton = document.createElement('button');51 backToTopButton.innerHTML = '<i data-feather="arrow-up"></i>';52 backToTopButton.className = 'fixed bottom-6 right-6 bg-blue-600 text-white p-3 rounded-full shadow-lg hover:bg-blue-700 transition-all opacity-0 invisible';53 document.body.appendChild(backToTopButton);54 55 window.addEventListener('scroll', () => {56 if (window.scrollY > 300) {57 backToTopButton.classList.remove('opacity-0', 'invisible');58 backToTopButton.classList.add('opacity-100', 'visible');59 } else {60 backToTopButton.classList.add('opacity-0', 'invisible');61 backToTopButton.classList.remove('opacity-100', 'visible');62 }63 });64 65 backToTopButton.addEventListener('click', () => {66 window.scrollTo({67 top: 0,68 behavior: 'smooth'69 });70 });71 72 // Feather icons replacement73 if (typeof feather !== 'undefined') {74 feather.replace();75 }76 77 // Initialize tooltips78 tippy('[data-tippy-content]', {79 arrow: true,80 animation: 'shift-away',81 theme: 'light-border',82 });83});