jQuery调整大小

问题描述:

我将尝试用单词来阐明:我想知道是否可以通过jquery-ui-resizable来同时调整对象在4个面上的大小,以便该对象的中心保持在同一位置.

I'll try to make it clear with words : I would like to know if there is a way with jquery-ui-resizable to resize an object on the 4 sides at the same time, so that the center of the object stay at the same position.

这是沙箱 http://jsfiddle.net/V79Ge/

所以,这很像AspectRatio = true,但是当我从一侧调整对象的大小时,它将控制另外3侧

So, it's quite like the aspectRatio=true, but while I resize the object from one side, it would control the 3 other sides

谢谢你的线索!

您想要的效果是: jsFiddle示例 .

Is this the effect you're after: jsFiddle example.

jQuery:

$('#resizeMe').resizable({
    aspectRatio: true,
    resize: function(event, ui) {
        $(this).css({
            'top': parseInt(ui.position.top, 10) + ((ui.originalSize.height - ui.size.height)) / 2,
            'left': parseInt(ui.position.left, 10) + ((ui.originalSize.width - ui.size.width)) / 2
        });
    }
});

更新了代码和jsFiddle以使用ui.position和ui.originalSize.

updated code and jsFiddle to use ui.position and ui.originalSize.