Following this my other answer, developing more the code could be something like this (in asynchronous version):
var div = document.getElementById('log');
var textos = ['Hoje está um lindo dia!', 'Ontem também... lindo lindo!', 'Amanha ouvi dizer que vai chover... vamos ver...', 'Boa noite, até amanhã.', 'Bons sonhos...zzZZZzzzz......'];
function escrever(str, done) {
var char = str.split('').reverse();
var typer = setInterval(function() {
if (!char.length) {
clearInterval(typer);
return setTimeout(done, 500); // só para esperar um bocadinho
}
var next = char.pop();
div.innerHTML += next;
}, 100);
}
function limpar(done) {
var char = div.innerHTML;
var nr = char.length;
var typer = setInterval(function() {
if (nr-- == 0) {
clearInterval(typer);
return done();
}
div.innerHTML = char.slice(0, nr);
}, 100);
}
function rodape(conteudos, el) {
var atual = -1;
function prox(cb){
if (atual < conteudos.length - 1) atual++;
else atual = 0;
var str = conteudos[atual];
escrever(str, function(){
limpar(prox);
});
}
prox(prox);
}
rodape(textos);
If it is not necessary to clean as I put in the example above, then it can be simpler... something like:
function escrever(str, done) {
var char = str.split('').reverse();
var typer = setInterval(function() {
if (!char.length) {
clearInterval(typer);
return setTimeout(done, 500); // só para esperar um bocadinho
}
var next = char.pop();
div.innerHTML += next;
}, 100);
}
function rodape(conteudos, el) {
var atual = -1;
function prox(){
if (atual < conteudos.length - 1) atual++;
else atual = 0;
var str = conteudos[atual];
escrever(str, function(){
div.innerHTML = '';
prox();
});
}
prox();
}
rodape(textos);
What you’ve tried to do?
– user28595
I just used the same post code I quoted. I don’t understand JS, but I would like this code on my site.
– Victor Eyer
There are two alternatives. If you used any of them and tried to adapt without success, it would be interesting to add here the code you adapted, even if it doesn’t work, so it becomes a basis for a response.
– user28595
Both worked. But the purpose of the codes in that post is to display only one post. I made no changes, I don’t understand javascript, only PHP.
– Victor Eyer