gpt4 book ai didi

jquery - 使用 jQuery 在设定时间后更改文本颜色,并无限重复

转载 作者:行者123 更新时间:2023-12-01 02:59:36 25 4
gpt4 key购买 nike

我找到了这个答案:

How can I change text after time using jQuery?

这基本上满足了我的需要。但我不想让它在最后重定向到另一个页面,而是希望它继续无限地循环浏览短信。显然,我删除了 IF 部分以停止重定向,但如何让它重复循环短信?

function nextMsg() {
if (messages.length == 0) {
// once there is no more message, do whatever you want
alert("redirecting");
} else {
// change content of message, fade in, wait, fade out and
// continue with next message
$('#message').html(messages.pop()).fadeIn(500).delay(1000)
.fadeOut(500, nextMsg);
}
};

// list of messages to display var messages = [
// "Hello!",
// "This is a website!",
// "You are now going to be redirected.",
// "Are you ready?",
// "You're now being redirected..."
// ].reverse();

// initially hide the message $('#message').hide();

// start animation nextMsg();

最佳答案

只需对基本代码进行一些小的更改:

function nextMsg(i) {
if (messages.length == i) {
i = 0;
}

$('#message').html(messages[i])
.fadeIn(500)
.delay(1000)
.fadeOut(500, function() {
nextMsg(i + 1);
});
};

nextMsg(0);​

演示: http://jsfiddle.net/8wqv2/

关于jquery - 使用 jQuery 在设定时间后更改文本颜色,并无限重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12572305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com