I was wondering if there was any way to make the typing text come in as different font sizes. I have attached a jsfiddle that shows what I have done so far. Is there a way to assign a class to each sentence?
Thank you!
https://jsfiddle.net/te4fo7fh/embedded/result/
var tt_element = document.getElementById("tt_element");
var tt_text = "It would be great if this sentence came in 12pt fontsize.^with the typing effect being editable.^^And this one came in 30pt font size.";
var tt_array = tt_text.split("");
var tt_timer;
var tt_loop = true;
var tt_speed = 70;
var tt_delay = 3000;
var tt_br = "^";
function typeMyText() {
if (tt_array.length > 0) {
if (tt_array[0] == tt_br) {
tt_element.innerHTML += "<br>";
tt_array.shift();
} else {
tt_element.innerHTML += tt_array.shift();
}
} else {
clearTimeout(tt_timer);
if (tt_loop) {
setTimeout(clearMyText, tt_delay);
}
return false;
}
tt_timer = setTimeout(typeMyText, tt_speed);
}
typeMyText();
#tt_element {
padding-top: 20px;
line-height:1.5em;
font-size: 12pt;
font-family: Georgia;
}
<section class="editable" contenteditable="true">
<p id="tt_element" class="blue"></p>
</section>
I updated your example.
First of all you type the wished fontSize into your string like your breaks.
After that you put every line into a single
span
.Once you've done that you still need to recognize the fontSize change:
See the fiddle here: https://jsfiddle.net/te4fo7fh/1/
You could replace
tt_text
by an array of objects, which embed style information (tt_text_with_style
in my example).I think you have use
Typed.js
Which has many options to play with. Here is link for that : Type.jsHere is some example code with this js :
Add this for the animated blinking cursor.