vUX / Resizer / v4.1.0

Grab an edge.
Drag it.

A drag handle on any element, on either axis, clamped to bounds you set.

760 × 280

Drag the right edge or the bottom edge.

min 220×120 · max 980×520
resizer.config.resizeHandlerProperties = { parent: box, direction: "both" }

01Playground

Every config property, wired to one box. Changing a setting tears the Resizer down with destroy() and builds a new one: config is read at initialize(), so a live instance cannot be reconfigured in place.

config

0 means unset, not zero: it is the sentinel the module uses to skip a clamp.

idle
live
drag an edge
resizedWidth 300 resizedHeight 200 callBack ×0
equivalent code

                

02Your own handle

Set config.myResizeHandler to a class name and the module stops building handles: it listens for a mousedown on your element instead. The grip below is a sibling of the panel it resizes, not a child of it, and it holds an icon: a mousedown landing on that icon still counts, because the module walks up from the event target.

config.myResizeHandler = "grip" 270px
●●●

Content

Nothing here is managed by vUX. The sidebar has a width, this column is flex:1, and the browser does the rest.

The grip carries no x or y class. It does not need one: direction is "x", which leaves the module only one axis to pick.

03All four edges

A handle grows the element in the direction it faces. Drag the left handle left, or the top handle up, and the box gets bigger: the travelled distance is inverted for those two edges.

x · right

drag →

x · left

← drag

y · bottom

drag ↓

y · top

↑ drag

The module writes a size, never a position. Growing leftward or upward is this page anchoring each box to the far side of its cell with flexbox; without that the box would still change size, but it would visibly grow the other way.

04Teardown

destroy() unregisters the module's listeners and removes the handles it injected. Anything hosting a Resizer inside a view that comes and goes (an SPA route, a modal) needs it.

targethandles in the DOM: 0
drag the right edge

Both methods are safe to call twice. initialize() on a live instance returns immediately rather than appending a second set of handles, listeners and stylesheets.


                

05Bad input fails immediately

Every setter validates and throws, naming the property and what it wanted. Press a button to run the call and print the real Error.

No error yet.