diff --git a/bihar-culture-landing/culture.html b/bihar-culture-landing/culture.html index 8a8da57..8df3ba3 100644 --- a/bihar-culture-landing/culture.html +++ b/bihar-culture-landing/culture.html @@ -103,6 +103,8 @@

Want to Contribute to Bihar’s Cultural Archive?

Celebrating the spirit, art, and heritage of Bihar.

+ + diff --git a/bihar-culture-landing/festivals.html b/bihar-culture-landing/festivals.html index 5b4bf2f..bbe5031 100644 --- a/bihar-culture-landing/festivals.html +++ b/bihar-culture-landing/festivals.html @@ -79,5 +79,6 @@

Shravani Mela

Bihar's rich heritage reflected in it's festivals


+ diff --git a/bihar-culture-landing/history.html b/bihar-culture-landing/history.html index f812299..9016726 100644 --- a/bihar-culture-landing/history.html +++ b/bihar-culture-landing/history.html @@ -39,5 +39,6 @@

Freedom Fighters

+ diff --git a/bihar-culture-landing/index.html b/bihar-culture-landing/index.html index 16451cd..61b9003 100644 --- a/bihar-culture-landing/index.html +++ b/bihar-culture-landing/index.html @@ -125,25 +125,6 @@

Contribute to Bihar Culture

- - - - diff --git a/bihar-culture-landing/modern.html b/bihar-culture-landing/modern.html index bb1ab32..9d535f4 100644 --- a/bihar-culture-landing/modern.html +++ b/bihar-culture-landing/modern.html @@ -39,5 +39,6 @@

Bihar in Cinema

+ diff --git a/bihar-culture-landing/script.js b/bihar-culture-landing/script.js index f89adb2..dc1df74 100644 --- a/bihar-culture-landing/script.js +++ b/bihar-culture-landing/script.js @@ -9,6 +9,7 @@ document.addEventListener('DOMContentLoaded', function() { initAccessibility(); initProgressiveEnhancement(); initQuiz(); // attach quiz logic if present + initBackToTop(); // initialize back-to-top button across pages }); // Navigation enhancements @@ -447,4 +448,69 @@ document.head.appendChild(style); // Export for module usage (if needed) if (typeof module !== 'undefined' && module.exports) { module.exports = BiharCulture; +} + +// Back to Top button: create a single reusable button and behavior across pages +function initBackToTop() { + try { + if (document.getElementById('backToTopBtn')) return; // already present + + const btn = document.createElement('button'); + btn.id = 'backToTopBtn'; + btn.type = 'button'; + btn.title = 'Back to Top'; + btn.setAttribute('aria-label', 'Back to top'); + btn.innerHTML = '↑'; + btn.style.display = 'none'; + + // Make sure the button is added after the rest of content + document.body.appendChild(btn); + + const showThreshold = 200; + + const updateVisibility = () => { + const scrolled = window.pageYOffset || document.documentElement.scrollTop; + if (scrolled > showThreshold) { + btn.style.display = 'block'; + } else { + btn.style.display = 'none'; + } + }; + + // Throttle using requestAnimationFrame for better perf + let ticking = false; + window.addEventListener('scroll', () => { + if (!ticking) { + window.requestAnimationFrame(() => { + updateVisibility(); + ticking = false; + }); + ticking = true; + } + }, { passive: true }); + + // Smooth scroll while respecting user preference for reduced motion + btn.addEventListener('click', () => { + const prefersReduced = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches; + if (prefersReduced) { + window.scrollTo(0, 0); + } else { + window.scrollTo({ top: 0, behavior: 'smooth' }); + } + btn.blur(); + }); + + // Keyboard accessibility (Enter/Space) + btn.addEventListener('keydown', (e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + btn.click(); + } + }); + + // Initialize visibility on load + updateVisibility(); + } catch (err) { + console.error('BackToTop initialization failed:', err); + } } \ No newline at end of file