diff options
| author | Danilo M. <danix@danix.xyz> | 2026-04-05 08:40:09 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-04-05 08:40:09 +0200 |
| commit | dcf54cad8529526fd7f8d9d4b84b63ccb3fa9630 (patch) | |
| tree | ddd752bb91a333eb7f8f3f7bcf41a4f75c8cd460 /assets/js/progress-bar.js | |
| parent | b1d3e5315bf92b925a1ca0603c2e476ae8c3d306 (diff) | |
| download | danixxyz-theme-dcf54cad8529526fd7f8d9d4b84b63ccb3fa9630.tar.gz danixxyz-theme-dcf54cad8529526fd7f8d9d4b84b63ccb3fa9630.zip | |
feat: add JavaScript modules (theme toggle, matrix rain, progress tracking, copy-to-clipboard)
Implement all 4 JavaScript modules:
- theme-toggle.js: Theme switching with localStorage persistence
- matrix-rain.js: Animated matrix-style rain effect on canvas
- progress-bar.js: Reading progress tracking during scroll
- copy-code.js: Copy-to-clipboard functionality for code blocks
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Diffstat (limited to 'assets/js/progress-bar.js')
| -rw-r--r-- | assets/js/progress-bar.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/assets/js/progress-bar.js b/assets/js/progress-bar.js new file mode 100644 index 0000000..bc8b70a --- /dev/null +++ b/assets/js/progress-bar.js @@ -0,0 +1,38 @@ +// progress-bar.js +(function() { + const progressBar = document.querySelector('.reading-progress'); + if (!progressBar) return; + + // Only enable on pages with substantial content + const mainContent = document.querySelector('main'); + if (!mainContent) return; + + function updateProgress() { + // Calculate scroll percentage + const windowHeight = window.innerHeight; + const docHeight = document.documentElement.scrollHeight - windowHeight; + const scrolled = window.scrollY; + const percent = docHeight > 0 ? (scrolled / docHeight) * 100 : 0; + + progressBar.style.width = percent + '%'; + } + + // Mark body as scrollable if there's significant content + const contentHeight = mainContent.offsetHeight; + if (contentHeight > window.innerHeight * 1.5) { + document.body.classList.add('scrollable'); + } + + // Use requestAnimationFrame for smooth updates + let ticking = false; + window.addEventListener('scroll', function() { + if (!ticking) { + requestAnimationFrame(updateProgress); + ticking = true; + setTimeout(() => { ticking = false; }, 100); + } + }, { passive: true }); + + // Initial update + updateProgress(); +})(); |
