gridstack.js icon indicating copy to clipboard operation
gridstack.js copied to clipboard

Resizing elements triggers window resize event repeatedly

Open DanielFrench87 opened this issue 9 years ago • 4 comments

Hello,

I'm having an issue when resizing elements via dragging. The window's resize event appears to be triggered repeatedly for every mouse movement, causing some slow down in my application. I have replicated this on a gridstack demo page by logging to console on window resize.

http://gridstackjs.com/demo/responsive.html

Do you know if there is a workaround for this please?

DanielFrench87 avatar Sep 12 '17 16:09 DanielFrench87

Hey, @Metal101 ! Try out lodash's debounce method.

http://jsfiddle.net/rifat/ZDPaV/

and

https://lodash.com/docs/#debounce

Let me know if there's anything more I can help with!

radiolips avatar Sep 12 '17 18:09 radiolips

hi @radiolips. this solution is only ok if you are writing everything from scratch. if i have an existing application 100's of handlers on windows resize are you expecting all of these to be re-written. Ultimately the window isn't resizing so surely this event should not be triggered. Are you able to re-open this bug?

ashw1984 avatar Sep 13 '17 09:09 ashw1984

@ashw1984 has directed me to this page.

https://stackoverflow.com/questions/7494378/jquery-ui-resizable-fire-window-resize-event

It's suggested you catch the element resize event and stop propagation before it bubbles up to the window event.

DanielFrench87 avatar Sep 13 '17 13:09 DanielFrench87

This is a jquery-ui "bug," not a gridstack bug. We're working to move away from jquery-ui, but in the meantime, you can check event.target as the SO mentions.

radiolips avatar Sep 13 '17 15:09 radiolips