I'm trying to adapt the code from this answer, however I can't get it to work like I would like it to.
I have some text in a <p>
and I would like to have this text replaced with some other text and then repeat.
E.g. text1
> >
text2
> >
text1
>...
I don't need any button or slider, just the fade-in, fade-out.
Thanks in advance!
My code:
HTML
<div class="fadey">Hallo</div>
<div class="fadey">Bonjour</div>
CSS
.myFade {
position: absolute;
height: 50px;
width: 50px;
}
JS
$(document).ready(function () {
var faderIndex = 0,
faderOutSpeed = 2000,
faderInSpeed = 3000,
faders = $('.fadey');
function nextFade() {
$(faders[faderIndex]).fadeOut(1000, function () {
faderIndex++;
if (faderIndex >= faders.length) faderIndex = 0;
$(faders[faderIndex]).fadeIn(1000, nextFade);
});
}
nextFade();
});
How can I add a delay that let's the text stay a little longer visible before vanishing?