Can html text in p tag is resizable using jquery-ui or without p tag in a div tag is resizable? I have done resizing the image using jquery ui from following example but text is not getting resized http://jqueryui.com/demos/resizable/.
Asked
Active
Viewed 4,827 times
2 Answers
9
You may use resize event handler. The trick is how to calculate new font size. Check this solution as a variant:
Html:
<div id="resizable" class="ui-widget-content">
<h3 class="ui-widget-header">Resizable</h3>
<div id="content">Quis non magna sagittis, et cras tortor nunc? Enim, lectus et quis penatibus enim augue eros, dis sit sit urna cras placerat sociis porta</div>
</div>
Javascript:
var initDiagonal;
var initFontSize;
$(function() {
$("#resizable").resizable({
alsoResize: '#content',
create: function(event, ui) {
initDiagonal = getContentDiagonal();
initFontSize = parseInt($("#content").css("font-size"));
},
resize: function(e, ui) {
var newDiagonal = getContentDiagonal();
var ratio = newDiagonal / initDiagonal;
$("#content").css("font-size", initFontSize + ratio * 3);
}
});
});
function getContentDiagonal() {
var contentWidth = $("#content").width();
var contentHeight = $("#content").height();
return contentWidth * contentWidth + contentHeight * contentHeight;
}
You may look this solution at jsFiddle: jsFiddle link

Yuriy Rozhovetskiy
- 22,270
- 4
- 37
- 68
-
Thanks very much. Thanks very much for help i was really looking for that thanks very much. – Ali Nouman Sep 28 '11 at 14:09
-
Good stuff. I didn't quite understand the question! – rooney Sep 28 '11 at 15:43
-
Why do you multiply by 3? Sorry I don't get it where does it come from? – edgarjs Aug 08 '12 at 17:14
2
Text sizing has nothing to do with jQuery specifically. You can tie a CSS property to a slider, however.
$('#slideBar').slider({
startValue: 12,
minValue: 0,
maxValue: 100,
stop: function(e, ui) {
$("#text").css({fontSize: ui.value + 8});
}
});

rooney
- 947
- 1
- 7
- 16