I have a div element which is made jquery Resizable. It has alsoResize option set, so other elements resize simultaneously.
What I want to do, is to set size of this Resizable div element programmatically in such way, that all Resizable logic is triggered (especially this alsoResize option is taken into account).
How can I achieve that?
Update: It looks like the internals of jQuery UI have changed dramatically since I answered this and firing the event no longer works.
There’s no direct way to fire the event anymore because the resizable plugin has been fundamentally changed. It resizes as the mouse is dragged rather than syncing items up at the end. This happens by it listening for the internal
resizepropagation event for resizable plugins which is now fired by the_mouseDraghandler. But it depends on variables set along the way, so just firing that even internally won’t help.This means even overriding it is messy at best. I’d recommend just manually resizing the
alsoResizeelements directly, independent of the UI widget altogether if that’s possible.But for fun let’s say it isn’t. The problem is that the internals of the plugin set various properties relating to previous and current mouse position in order to know how much to resize by. We can
abuseuse that to add a method to the widget, like this:This is just creating the mouse events that the
resizablewidget is looking for and firing those. If you wanted to do something likeresizeByit’d be an even simpler end since all we care about is the delta:You’d call the
$.widget()method after jQuery UI and before creating your.resizable()instances and they’ll all have aresizeTomethod. That part doesn’t change, it’s just:Then to resize, you’d call that new
resizeTomethod like this:This would act as if you instantly dragged it to that size. There are of course a few gotchas here:
"se"axis is assuming you want resize by the bottom right – I picked this because it’s by far the most common scenario, but you could just make it a parameter.You can play with it in action with a fiddle here and the
resizeByversion here.Original answer:
You can do this:
alsoResizeinternally rigs up a handler to theresizeevent, so you just need to invoke that 🙂