views:

203

answers:

2

This jQuery lets you constrain drag movement so it occurs only on the axis specified:

$("#draggable2").draggable({ axis: 'x' });

See: http://jqueryui.com/demos/draggable/#constrain-movement

This is not legal jQuery but I wish it were:

$("#Container").resizable({ minHeight: 150, containment: {axis:'y' } });

Is it possible to prevent the user from making #Container wider while allowing her to make it taller?

Thanks

A: 

I see two ways for you to do this, one better than the other. The best one first:

1) Set minWidth and maxWidth to the same value (namely the value you want the width to remain).

$('#theThing').resizable({ minWidth = 200, maxWidth = 200 });

2) Create a parent element with fixed width and make that the containment. I don't know how this will work on the height, but by default a div with no height specified grows if its content does, so it might work.

Tomas Lycken
Thanks for the suggestion, Tomas. Unfortunately, when #theThing is contained inside #Container and #Container has no explicit height: $("#theThing").resizable({ minHeight: 150, containment: '#Container' }) then theThing cannot be resized vertically. #Container simply does not grow beyond the height it needs to render #theThing in the first place.
Tim
@Tim, did you try the other way - setting min and max width to the same value? This is what I'd do, rather than having a container.
Tomas Lycken
A: 

Yes, it's possible by using UI events. Along the x-axis:

$("#Container").resizable({
    resize: function(event, ui) {
        ui.size.width = ui.originalSize.width;
    }
});

or along the y-axis:

$("#Container").resizable({
    resize: function(event, ui) {
        ui.size.height = ui.originalSize.height;
    }
});
Dmitry