0
我试图附加处理程序来调整$('oWrapper_'+num)
。但它不会调整大小。如果这个问题是因为处理程序连接到错误的div,我不是这样吗?使用jQuery可调整大小的处理程序附加并调整div大小
我需要的是能够将处理器连接到$('oWrapper_'+num)
,并能够使用处理程序来调整。
num++
var cloudWrap = $('<div />', { id: 'cloudWrap_'+num}),
outerWrap = $('<div />').appendTo(cloudWrap)
outerWrap.append(
$('<div />', { class: 'tf', id: 'oWrapper_'+num, style: 'white-space:pre-line; font-size: 2vw;' }),
$('<div />', { class: 'ui-resizable-handle ui-resizable-ne hndl' }),
$('<div />', { class: 'ui-resizable-handle ui-resizable-se hndl' }),
$('<div />', { class: 'ui-resizable-handle ui-resizable-sw hndl' }),
$('<div />', { class: 'ui-resizable-handle ui-resizable-nw hndl' })
);
jQuery('#oWrapper_'+num).resizable({
handles: {
'ne': '.ui-resizable-ne',
'se': '.ui-resizable-se',
'sw': '.ui-resizable-sw',
'nw': '.ui-resizable-nw'
},
aspectRatio: 16/9,
});
编辑:
outerWrap.resizable({
handles: {
'ne': '.ui-resizable-ne',
'se': '.ui-resizable-se',
'sw': '.ui-resizable-sw',
'nw': '.ui-resizable-nw'
},
aspectRatio: 16/9,
create: function(event, ui) {
initDiagonal = getContentDiagonal();
initFontSize = parseInt($("#oWrapper_"+num).css("font-size"));
},
resize: function(e, ui) {
var newDiagonal = getContentDiagonal();
var ratio = newDiagonal/initDiagonal;
$("#oWrapper_"+num).css("font-size", (initFontSize/100) + (ratio/(initFontSize/1000)) + "vw");
}
});
function getContentDiagonal() {
var contentWidth = $("#oWrapper_"+CretCount).width();
var contentHeight = $("#oWrapper_"+CretCount).height();
return contentWidth * contentWidth + contentHeight * contentHeight;
}
感谢您的答复阿伦。看来这不是问题。处理程序连接完美。我唯一的问题是它没有调整大小?我觉得处理程序没有附加到'#oWrapper _'+ num',我正在尝试调整'#oWrapper _'+ num'的大小。所以这不是调整大小? – Fergoso 2015-03-03 10:49:31
@Fergoso http://jsfiddle.net/arunpjohny/e865rerd/4/ – 2015-03-03 10:59:49
@Fergoso代码http://jsfiddle.net/arunpjohny/e865rerd/5/ – 2015-03-03 11:00:13