Round grid scroll wrapper offsets to the nearest pixel

This commit is contained in:
Andrew Kingston 2024-06-27 15:51:57 +01:00
parent 8e83046321
commit c62e6d776c
No known key found for this signature in database
1 changed files with 5 additions and 3 deletions

View File

@ -27,9 +27,11 @@
$: style = generateStyle($scroll, $rowHeight) $: style = generateStyle($scroll, $rowHeight)
const generateStyle = (scroll, rowHeight) => { const generateStyle = (scroll, rowHeight) => {
const offsetX = scrollHorizontally ? -1 * scroll.left : 0 const offsetX = Math.round(scrollHorizontally ? -1 * scroll.left : 0)
const offsetY = scrollVertically ? -1 * (scroll.top % rowHeight) : 0 const offsetY = Math.round(
return `transform: translate3d(${offsetX}px, ${offsetY}px, 0);` scrollVertically ? -1 * (scroll.top % rowHeight) : 0
)
return `transform: translate(${offsetX}px, ${offsetY}px);`
} }
// Handles a mouse wheel event and updates scroll state // Handles a mouse wheel event and updates scroll state