淡入淡出文本并重复

时间:2018-01-27 21:20:13

标签: javascript html

我正在尝试调整this answer中的代码,但是我无法像我希望的那样让它工作。

我在<p>中有一些文字,我希望将此文字替换为其他文字,然后重复。

E.g。 text1&gt; &gt; text2&gt; &gt; text1&GT; ...

我不需要任何按钮或滑块,只需要淡入淡出。

提前致谢!

我的代码:

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();
});

如何添加延迟,让文字在消失之前保持更长时间可见?

0 个答案:

没有答案
相关问题