言葉で明確にしようと思います:jquery-ui-resizableを使用して、オブジェクトの中心が同じ位置。
これがサンドボックスですhttp://jsfiddle.net/V79Ge/
つまり、aspectRatio = trueとよく似ていますが、オブジェクトのサイズを一方の側から変更すると、他の3つの側が制御されます。
手がかりをありがとう!
言葉で明確にしようと思います:jquery-ui-resizableを使用して、オブジェクトの中心が同じ位置。
これがサンドボックスですhttp://jsfiddle.net/V79Ge/
つまり、aspectRatio = trueとよく似ていますが、オブジェクトのサイズを一方の側から変更すると、他の3つの側が制御されます。
手がかりをありがとう!
これはあなたが求めている効果ですか:jsFiddleの例。
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
});
}
});
編集:ui.positionとui.originalSizeを使用するようにコードとjsFiddleを更新しました。
サンドボックスを少しいじって、これを手に入れました。
$('#resizeMe').resizable({
aspectRatio: true,
resize: function(event, ui) {
$(this).offset({ top: (ui.originalSize.height-ui.size.height)/2,left:(ui.originalSize.width-ui.size.width)/2});
}
});
j08691の例をいくつか更新しました。今では北西のハンドルでも動作します。
http://jsfiddle.net/j08691/V79Ge/19/
$('#resizeMe').resizable({
aspectRatio: true,
handles: 'all',
resize: function(event, ui) {
var posTop = parseInt(ui.position.top, 10);
var posLeft = parseInt(ui.position.left, 10);
var oPosTop = parseInt(ui.originalPosition.top, 10);
var pPosLeft = parseInt(ui.originalPosition.left, 10);
if(posTop == oPosTop && posLeft == pPosLeft)
{
$(this).css({
'top': posTop + ((ui.originalSize.height - ui.size.height)) / 2,
'left': posLeft + ((ui.originalSize.width - ui.size.width)) / 2
});
}
else {
var width = ui.size.width;
var height = ui.size.height;
var oWidth = ui.originalSize.width;
var oHeight = ui.originalSize.height;
$(this).css({
'width': width + (width - oWidth),
'height': height + (height - oHeight)
});
}
}});
それはまださらなる開発が必要です。すべてのハンドルで機能するわけではありません。
$(".nodecontainer").each(function () {
$(this).parent().attr('style', $(this).attr('style'));
$(this).spectrum({
showPalette: true,
change: function (color) {
$(this).parent().css('background-color', color.toHexString());
},
palette: [
['black', 'white', 'blanchedalmond'],
['rgb(255, 128, 0);', 'hsv 100 70 50', 'lightyellow']
]
})
});;
$('.nodecontainer').each(function () {
$(this).resizable({
alsoResize: $(this).parent(),
resize: function (e, ui) {
$(this).css("top", 0);
$(this).css("left",0);
$(this).css("position","relative");
}
});
});