fix: better autoscroll
continuous-integration/drone/push Build is passing Details

main
parent aeeda341fc
commit 3b3ec6df3e

@ -55,13 +55,15 @@ export const LiveLeaderboard = ({ roomId }: Props) => {
const timerRef = useRef<Timer | null>(null)
useEffect(() => {
const PIXELS_PER_MILLISECOND = [1, 1000 / 30] // e.g. [1, 10] means 1px every 10ms
if (autoscroll !== false) {
timerRef.current = setInterval(() => {
console.log('scrolling')
window.scrollBy({
top: autoscroll === 'down' ? 10 : -10,
behavior: 'smooth',
top: autoscroll === 'down' ? PIXELS_PER_MILLISECOND[0] : -PIXELS_PER_MILLISECOND[0],
behavior: 'instant',
})
if (window.scrollY + window.innerHeight + 1 > document.body.scrollHeight) {
@ -71,7 +73,7 @@ export const LiveLeaderboard = ({ roomId }: Props) => {
if (window.scrollY === 0) {
setAutoscroll('down')
}
}, 100)
}, PIXELS_PER_MILLISECOND[1])
return () => {
if (timerRef.current) {

Loading…
Cancel
Save