I am trying to manually wrap text that overlays an image. At the moment I have a text input box where the user can type a sentence, the overlay text updates the displayed text on each key up press. The overlay text is using text transformations to curve and reshape the text, so it will not auto wrap to a new line. And the input field is a fixed size larger than the wrapping cut off length.
I have tried to break for a new line if the text is over 10 characters, but this doesn't account for if it is in the middle of a word. How can I detect the end of the last word and break there instead?
Thanks for any help.
$("input[name='text']").keyup(function(event) {
var text = $(this).val();
var breakText = '';
while (text.length > 0) {
breakText += text.substring(0, 10) + '\n';
text = text.substring(10);
}
$("p.overlay").html(breakText);
});
A width cannot be added to the overlaid text because it loops in a circle like a spiral and goes back in on itself. The width has no wrapping effect on the text unfortunately.