mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-28 08:59:40 +05:00
Merge remote-tracking branch 'origin/feat_player'
This commit is contained in:
parent
bb437fe7ca
commit
25e31a7799
62 changed files with 1508 additions and 701 deletions
26
app/hooks/useScrollPosition.ts
Normal file
26
app/hooks/useScrollPosition.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useScrollPosition() {
|
||||
const [scrollPosition, setScrollPosition] = useState(0);
|
||||
|
||||
function handleScroll() {
|
||||
const height =
|
||||
document.documentElement.scrollHeight -
|
||||
document.documentElement.clientHeight;
|
||||
|
||||
const windowScroll = document.documentElement.scrollTop;
|
||||
|
||||
const scrolled = (windowScroll / height) * 100;
|
||||
|
||||
setScrollPosition(scrolled);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener("scroll", handleScroll, { passive: true });
|
||||
return () => {
|
||||
window.removeEventListener("scroll", handleScroll);
|
||||
};
|
||||
});
|
||||
|
||||
return Math.floor(scrollPosition);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue