Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Text = function (object) {
- this.text = object.text;
- this.el = object.el;
- this.total = this.text.length;
- this.current = 0;
- this.timeout;
- this.timeoutAnim = object.timeoutAnim || 300;
- };
- Text.prototype.startAnimation = function () {
- this.timeout = setInterval(() => this.animate(), this.timeoutAnim);
- };
- Text.prototype.animate = function () {
- this.el.innerHTML += this.text[this.current++];
- if (this.current == this.total)
- clearTimeout(this.timeout);
- };
- document.body.innerHTML = "";
- var anim = new Text({
- text: "Olá, tudo bem? Como vai as coisas?",
- el: document.body,
- timeoutAnim: 100
- });
- anim.startAnimation();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement