[英]How to display text for some amount of time in JavaScript?
我正在使用JavaScript制作游戲..所以,我想顯示“你贏了!” 文本 5 秒。但是當我執行它時,它只顯示文本的時間很短,然后消失了。
{
//If Sofia touches the CUP then there should be a timeout for n seconds
textSize(30);
text("YOU WIN!!!", 200, 100);
sofia.x = 380;
sofia.y = 375;
}
Sofia 是球員的名字,CUP 就像是 Sofia 的終點線。
sofia.x = 380;
sofia.y = 375;
這段代碼是讓Sofia在觸到Cup后回到初始位置。
所以,基本上我想顯示“你贏了!” 一段時間(比如... 5 秒)。
您將顯示該消息並在 5 秒后將其刪除。
document.getElementById("idOfBlock").innerHTML = msg;
setTimeout(function(){
document.getElementById("idOfBlock").innerHTML = '';
}, 5000);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.