vaheqelyan / svelte-grid

A responsive, draggable and resizable grid layout, for Svelte.

Home Page:https://svelte-grid.now.sh/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Items slow to reposition on resize

ksallee opened this issue · comments

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:

Screen.Recording.2022-06-10.at.16.26.59.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)
}