[英]How to increase text inside div with its size
我在容器div中添加了多個動態div。 每個div包含文本。 它的作品很好。 但是,當我使用jquery庫將可調整大小的功能添加到div中時。 我可以調整div的大小,但其文本大小是靜態的。 當我增加div大小時,我想要的是其文本大小也應增加,反之亦然。
下面是添加可調整大小功能並附加到父級的代碼。
var div = document.createElement('div');
$(div).attr("id", "dyndiv" + count);
objid = "dyndiv" + count ;
count++;
var $ctrl = $(div).text($('#txttext').val()).addClass("draggable ui-widget-content").draggable({ containment: '#containment-wrapper', cursor: 'move', snap: '#containment-wrapper' }).resizable({ aspectRatio:true, containment: '#containment-wrapper' });
$("#containment-wrapper").append($ctrl);
這是我的意思的示例,您可能需要弄亂計算,盡管要包括高度,但現在您可以減小高度,但不能完全容納在框中。
$( ".selector" ).resizable({
resize: function(event, ui) {
newSize = $(this).width()*0.1;
$(this).css('font-size', newSize );
}
});
就像是:
var $ctrl = $(div).text($('#txttext').val())
.addClass("draggable ui-widget-content")
.draggable({
containment: '#containment-wrapper',
cursor: 'move',
snap: '#containment-wrapper' })
.resizable({
aspectRatio:true,
containment: '#containment-wrapper',
resize: function(event, ui) {
newSize = $(this).width()*0.1;
$(this).css('font-size', newSize );
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.