jQuery调整大小 [英] jQuery resize on both sides
本文介绍了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.
这篇关于jQuery调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文