diff options
| author | Your Name <[email protected]> | 2025-11-14 20:45:04 -0500 |
|---|---|---|
| committer | Your Name <[email protected]> | 2025-11-14 20:45:04 -0500 |
| commit | e3aa629c7f8f8827dd540d5582e50b67dc53de07 (patch) | |
| tree | 9f9555e0d3c8ea96335685c645bb478a163338be /js/parallax-header.js | |
| parent | 1743bc1b52f390e3942158fa7e911417bc869ee3 (diff) | |
| download | malcz-wordpress-theme-e3aa629c7f8f8827dd540d5582e50b67dc53de07.tar.gz malcz-wordpress-theme-e3aa629c7f8f8827dd540d5582e50b67dc53de07.zip | |
progress
Diffstat (limited to 'js/parallax-header.js')
| -rw-r--r-- | js/parallax-header.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/js/parallax-header.js b/js/parallax-header.js new file mode 100644 index 0000000..c4ce1fc --- /dev/null +++ b/js/parallax-header.js @@ -0,0 +1,20 @@ +const targetMin = -10; +const targetMax = 25; +let currentPercent = targetMin; +let targetPercent = targetMin; +const tweenSpeed = 0.040; + +document.addEventListener("scroll", () => { + const scrollTop = window.scrollY; + const docHeight = document.documentElement.scrollHeight - window.innerHeight; + let scrollFraction = scrollTop / docHeight; + targetPercent = targetMin + (targetMax - targetMin) * scrollFraction; +}); + +function animate() { + currentPercent += (targetPercent - currentPercent) * tweenSpeed; + document.documentElement.style.setProperty('--scroll-percent', currentPercent + '%'); + requestAnimationFrame(animate); +} + +animate(); |
