export function ScrollToTop() {
const circleRef = React.useRef();
React.useEffect(() => {
const circleLength = circleRef.current.getTotalLength();
window.addEventListener("scroll", () => {
const getSctollTop = () => {
return window.pageYOffset || document.documentElement.scrollTo;
}
const updateDashoffset = () => {
const heigth = document.documentElement.scrollHeight - window.innerHeight;
const dashoffset = circleRef.current - (getSctollTop() * circleLength / heigth);
circleRef.current.style.strokeDashoffset = dashoffset
};
updateDashoffset()
});
}, []);
return (
<svg onClick={isStart} width="50" height="50" viewBox="0 0 50 50" className={styles.circle_svg}>
<circle ref={circleRef} cx="25" cy="25" r="23.5" fill="none"/>
</svg>
)
}
const dashoffset = circleRef.current - ...
NaN
.const getSctollTop = () => { return window.pageYOffset || document.documentElement.scrollTo; }
scrollTo
? Это же метод, а вы вроде бы число хотите получить. Может, scrollTop
?React.useEffect(() => { ... window.addEventListener("scroll", () => { ... }); }, []);