mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 21:58:03 +00:00
feat: updates
This commit is contained in:
parent
ce757215a3
commit
c1cd31840e
86 changed files with 1048 additions and 778 deletions
|
|
@ -1,15 +1,11 @@
|
|||
import { useState, useEffect, RefObject } from 'react'
|
||||
|
||||
const useIntersectionObserver = (
|
||||
element: RefObject<Element>
|
||||
): { onScreen: boolean } => {
|
||||
const useIntersectionObserver = (element: RefObject<Element>): { onScreen: boolean } => {
|
||||
const [onScreen, setOnScreen] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (element.current) {
|
||||
const observer = new IntersectionObserver(([entry]) =>
|
||||
setOnScreen(entry.isIntersecting)
|
||||
)
|
||||
const observer = new IntersectionObserver(([entry]) => setOnScreen(entry.isIntersecting))
|
||||
observer.observe(element.current)
|
||||
return () => {
|
||||
observer.disconnect()
|
||||
|
|
|
|||
|
|
@ -43,13 +43,10 @@ const useScroll = (
|
|||
|
||||
const arrivedState: ArrivedState = {
|
||||
left: target.scrollLeft <= 0 + (offset?.left || 0),
|
||||
right:
|
||||
target.scrollLeft + target.clientWidth >=
|
||||
target.scrollWidth - (offset?.right || 0),
|
||||
right: target.scrollLeft + target.clientWidth >= target.scrollWidth - (offset?.right || 0),
|
||||
top: target.scrollTop <= 0 + (offset?.top || 0),
|
||||
bottom:
|
||||
target.scrollTop + target.clientHeight >=
|
||||
target.scrollHeight - (offset?.bottom || 0),
|
||||
target.scrollTop + target.clientHeight >= target.scrollHeight - (offset?.bottom || 0),
|
||||
}
|
||||
|
||||
setScroll({
|
||||
|
|
@ -59,9 +56,7 @@ const useScroll = (
|
|||
})
|
||||
}
|
||||
|
||||
const readHandleScroll = throttle
|
||||
? lodashThrottle(handleScroll, throttle)
|
||||
: handleScroll
|
||||
const readHandleScroll = throttle ? lodashThrottle(handleScroll, throttle) : handleScroll
|
||||
|
||||
const element = 'current' in ref ? ref?.current : ref
|
||||
element?.addEventListener('scroll', readHandleScroll)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue