如何在文本RPG jQuery中推进文本

时间:2018-01-28 22:52:31

标签: javascript jquery

我正在创建一个小文本RPG,我有一些人说多行文字。我替换文本的当前方式如下。

HTML

<div class="textarea"></div>

JS / jQuery的

$('.textarea')
    .delay(1000)
    .text("Hello Brave Adventurer Blah blah blah")
    .fadeIn();

问题因此在于下一个文本块....如果我写一个新的.text(),程序只会调出最底部的文本框而不显示其他文本框

示例:

  $('.textarea')
        .delay(1000)
        .text("Hello Brave Adventurer Blah blah blah")
        .fadeIn()
        .fadeOut()
        .delay(1000)
        .fadeIn()
        .text('new text')

然后显示“新文本”,第一个文本“Hello Br ...”永远不会显示。

2 个答案:

答案 0 :(得分:0)

如果您同时向.fadeIn().fadeOut()提问jQuery,您希望它做什么?

相反,请尝试使用回调函数,如下所示:

.fadeIn('slow', function () {
    $(this).fadeOut('slow', function () {
        // etc...
    })
})

答案 1 :(得分:0)

尝试使用类似的东西:

$('.textarea')
    .hide()
    .text("Hello Brave Adventurer Blah blah blah")
    .fadeIn(1000)
    .fadeOut(1000, function(){$(this).text('new text')})
    .fadeIn(1000)
    .fadeOut(1000, function(){$(this).text('another new text')})
    .fadeIn(1000)

查看example