svelte-grid
svelte-grid copied to clipboard
Items slow to reposition on resize
When I resize the grid, the containers inside tend to overlap or stretch while resizing, and even with throttleUpdate
and throttleResize
set to a minimum, it doesn't seem to have any effect.
Is there a way to fix this?
Here's an example:
https://user-images.githubusercontent.com/57231302/173153633-1f4dc6ff-4d03-4148-8849-3d1eeb64e47a.mov
So i took a look at it and this behavior happens because the 0.2s transform in src/MoveResize/index.svelte triggers when resizing the grid.
{active
? transform: translate(${cordDiff.x}px, ${cordDiff.y}px);top:${rect.top}px;left:${rect.left}px;
: trans ? transform: translate(${cordDiff.x}px, ${cordDiff.y}px); position:absolute; transition: width 0.2s, height 0.2s;
: transition: transform 0.2s, opacity 0.2s; transform: translate(${left}px, ${top}px);
} ">`
I dont think there is a way to fix this by using the API. `
Created pull request #133.
In the meantime there is some kind of spaghetti fix that can be applied with the existing API. When resize is detected it overwrites all transitions on the elements for a short amount of time.
style:
.horribleSpaghettiFix :global(.svlt-grid-container) > :global(.svlt-grid-item) { transition: none !important; }
html:
<div class:horribleSpaghettiFix={cover}>
<Grid on:resize={resizeMoveHandler}>
...
<Grid/>
<div/>
javascript:
let timer
const resizeMoveHandler = () => {
stopItemMove=true
clearTimeout(timer)
timer = setTimeout(() => stopItemMove=false, 500)
}