+ 1

JavaScript animation error

Hi! :) I tried to make an JS typewriting animation but in my first attempt to see the output I got the Uncaught ReferenceError. If anyone could help me solve this out I would be grateful. THE CODE: var TxTtype = function(el, toRotate, period) { this.toRotate = toRotate; this.el = el; this.loopNum = 0; this.period = parseInt(period, 10) || 2000; this.txt = ""; this.tick(); this.isDeleting = false }; TxtType.prototype.tick = function() { var i = this.loopNum % this.toRotate.length; var fullTxt = this.toRotate[i]; if (this.isDeleting) { this.txt = fullTxt.substring(0, this.txt.length -1); } else { this.txt = fullTxt.substring(0, this.txt.length +1); } this.el.innerHTML = '<span class="wrap">'+this.txt+'</span>' var that = this; var delta = 200 - Math.random() *100; if (this.isDeleting){ delta /= 2; } if (!this.isDeleting && this.txt === fullTxt) { delta = this.period; this.isDeleting = true; } else if (this.isDeleting && this.txt === '') { this.isDeleting = false; this.loopNum++; delta = 500; } setTimeout(function() { that.tick(); }, delta); }; window.onload = function() { var elements = document.getElementsByClassName('typewrite'); for (var i=0; i<elements.length; i++) { var toRotate = elements[i].getAttribute('data-type'); var period = elements[i].getAttribute('data-period'); if (toRotate) { new TxtType(elements[i],JSON.parse(toRotae), period); } } //CSS part var css = document.createElement("style"); css.type = "text/css"; css.innerHTML = ".typewrite > .wrap { border-right: 0.08em solid #12937F}"; document.body.appendChild(css) };

3rd Sep 2018, 10:59 AM
Tyhe Ferenc
Tyhe Ferenc - avatar
3 odpowiedzi
+ 4
The first function has a semicolon after the closing bracket.
3rd Sep 2018, 12:59 PM
Theprogrammers
Theprogrammers - avatar
+ 3
Uncaught ReferenceError: (TxTtype) is not defined Line: 11. You need to look at line 1 and line 11 to resolve this problem. Then line 54. btw, you should put the h1, a, and span tags in the body of the document, not the head.
3rd Sep 2018, 1:32 PM
ODLNT
ODLNT - avatar
+ 1
Guys thank you a lot! I managed to solve it and works just fine. You definetly gave me an inspiration! :) until later
3rd Sep 2018, 6:59 PM
Tyhe Ferenc
Tyhe Ferenc - avatar