vaheqelyan / svelte-grid

A responsive, draggable and resizable grid layout, for Svelte.
https://svelte-grid.now.sh/
MIT License
948 stars 57 forks source link

Items slow to reposition on resize #125

Open ksallee opened 2 years ago

ksallee commented 2 years ago

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

WbaN314 commented 1 year ago

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. `

WbaN314 commented 1 year ago

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)
}