How to detect scroll position with smooth scroll? #540
Answered
by
sadeghbarati
maksderylo
asked this question in
FAQ
-
I want to keep the benefits of smooth scroll whilst being able to perform animations depending on scroll position |
Beta Was this translation helpful? Give feedback.
Answered by
sadeghbarati
Jun 14, 2023
Replies: 1 comment 1 reply
-
Hi, You can use const root = document.documentElement;
scrollbar.addListener(( { offset } ) => {
root.style.setProperty('--scrollbar-position-y', offset.y);
});
// when you need the variable
getComputedStyle(document.documentElement).getPropertyValue('--scrollbar-position-y'); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
maksderylo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
You can use
addListener
event and store scroll position with CSS variables likeOr use GSAP ScrollTrigger + ScrollTrigger scrollerProxy
https://codepen.io/GreenSock/pen/oNLqgBm