Using jQuery UI Resizable I'm trying to prevent resizing based on various rules. The built-in containment feature doesn't seem to work properly with absolutely positioned elements, and I would need something more flexible than that anyway.
Having something like this:
$( ".selector" ).resizable({ resize : function(event, ui) { /* ??? */ } });
How can I tell the "ui" object to prevent resizing?
Thanks.
Enable any DOM element to be resizable. With the cursor grab the right or bottom border and drag to the desired width or height.
jQuery resize() MethodThe resize event occurs when the browser window changes size. The resize() method triggers the resize event, or attaches a function to run when a resize event occurs.
The mouse trigger the mousedown event on the resizer. Then catch the mousemove event on the resizer to handle begin to resize. With the bottom-right resizer, when the user drags that resizer, the element's width will equal to the x position of the mouse minus the x position of the element.
Its been long time, but there is a solution to this problem in case somebody read this.
You just need to set the maxWidth
or minWidth
(depends on what you want to do) inside the resize
to stop it from resizing.
You can do something like the following:
minWidth: 300,
start: function(event, ui) {
// get it once so we don't get it hundreds of time inside resize
this.enforcedMinWidth = $(this).resizable("option", "minWidth");
},
resize: function(event, ui) {
// use whatever conditions you want to stop here
// in my original case, i was checking its width vs neighbor and
// stops the resizing accordingly, so change it to fit your case
if (ui.element.next().width() <= this.enforcedMinWidth) {
$(this).resizable("option", "maxWidth", ui.size.width);
}
},
stop: function(event, ui) {
// reset
$(this).resizable("option", "maxWidth", null);
// cleanup
delete this.enforcedMinWidth;
}
There is no standart option to stop the resizing at this version. You can disable the resizable but it will continue resizing and will stop the option to resize only in the next time you try.
$(".selector").resizable("disable");
Anyway i found that you can limit the resizing using the maxWidth and maxHeight property directly from the Resize Event.
$(".selector").resizable({
aspectRatio: true,
handles: 'all',
resize: function( event, ui ){
if(x > y){
(".selector").resizable("option","maxWidth",ui.size.width);
return;
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With