Jquery动画移动文本

时间:2013-11-01 00:21:16

标签: jquery html jquery-animate

当使用animate来更改html中的某些内容时,jquery动画“移动”/移动文本而不是仅替换文本。

点击此处:http://jsfiddle.net/x2VYn/

    function cycleIntro() {
        var whoArr = ["colleagues", "girlfriend", "homies", "nemesis", "lover", "dad", "mom", "brother", "sister", "enemies", "friends", "classmates", "best friend", "imaginary friend", "grandma'"];
        var whatArr = ["pool", "backgammon", "dart", "chess", "ping pong", "bob", "headsup poker", "ludo", "yatzy", "foosball", "tennis", "street basket", "golf", "water polo"];

        var whotxt = whoArr[Math.floor(Math.random() * whoArr.length)];
        while ($("#intro #who").html() == whotxt) {
            whotxt = whoArr[Math.floor(Math.random() * whoArr.length)];
        }
        var whattxt = whatArr[Math.floor(Math.random() * whatArr.length)];
        while ($("#intro #what").html() == whattxt) {
            whattxt = whatArr[Math.floor(Math.random() * whatArr.length)];
        }
        $("#intro #who").animate({ width: "toggle" }, 200, function () {
            $("#intro #who").html(whotxt).animate({ width: "toggle" }, 300, function () {
                $("#intro #what").delay(50).animate({ width: "toggle" }, 200, function () {
                    $("#intro #what").html(whattxt).animate({ width: "toggle" }, 300, function () {
                        setTimeout(cycleIntro, 1500);
                    });
                });
            });
        });
    }
    setTimeout(cycleIntro, 1500);

有谁知道如何调整这个?

1 个答案:

答案 0 :(得分:1)

将您正在操作的范围的vertical-align属性设置为bottom可解决此问题。我已经更新了小提琴here