I have some issues starting this function what am i doing wrong?
I want this to start writing when my menu has reached the section "topb".
This is the attempt from me:
var $el = $('.writer'),
txt = $el.text(),
txtLen = txt.length,
timeOut,
$topb = $('#topb'),
char = 0;
$el.text('|');
if (topb.hasClass('active')) {
(function typeIt() {
var humanize = Math.round(Math.random() * (200 - 30)) + 30;
timeOut = setTimeout(function () {
char++;
var type = txt.substring(0, char);
$el.text(type + '|');
typeIt();
if (char == txtLen) {
$el.text($el.text().slice(0, -1)); // remove the '|'
clearTimeout(timeOut);
}
}, humanize);
}())
};
This is the original function
var $el = $('.writer'),
txt = $el.text(),
txtLen = txt.length,
timeOut,
char = 0;
$el.text('|');
(function typeIt() {
var humanize = Math.round(Math.random() * (200 - 30)) + 30;
timeOut = setTimeout(function () {
char++;
var type = txt.substring(0, char);
$el.text(type + '|');
typeIt();
if (char == txtLen) {
$el.text($el.text().slice(0, -1)); // remove the '|'
clearTimeout(timeOut);
}
}, humanize);
}())
};