繁体   English   中英

如何增加div内文本的大小

[英]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); 

这是我的意思的示例,您可能需要弄乱计算,尽管要包括高度,但现在您可以减小高度,但不能完全容纳在框中。

http://jsfiddle.net/HpSwu/1/

$( ".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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM