summaryrefslogtreecommitdiffstats
path: root/themes/danix-xyz-hacker/assets/js/reading-progress.js
diff options
context:
space:
mode:
Diffstat (limited to 'themes/danix-xyz-hacker/assets/js/reading-progress.js')
-rw-r--r--themes/danix-xyz-hacker/assets/js/reading-progress.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/themes/danix-xyz-hacker/assets/js/reading-progress.js b/themes/danix-xyz-hacker/assets/js/reading-progress.js
new file mode 100644
index 0000000..ee1192f
--- /dev/null
+++ b/themes/danix-xyz-hacker/assets/js/reading-progress.js
@@ -0,0 +1,29 @@
+// Reading progress bar for single pages/articles
+(function() {
+ const progressBar = document.getElementById('reading-progress');
+
+ if (!progressBar) return;
+
+ function updateProgress() {
+ const windowHeight = window.innerHeight;
+ const documentHeight = document.documentElement.scrollHeight - windowHeight;
+ const scrollProgress = documentHeight > 0 ? (window.scrollY / documentHeight) * 100 : 0;
+ progressBar.style.width = scrollProgress + '%';
+ }
+
+ // Throttle the scroll event for better performance
+ let ticking = false;
+
+ window.addEventListener('scroll', function() {
+ if (!ticking) {
+ window.requestAnimationFrame(function() {
+ updateProgress();
+ ticking = false;
+ });
+ ticking = true;
+ }
+ }, false);
+
+ // Initial call
+ updateProgress();
+})();