jquery - 在倒计时的特定时间后更改问题以及是否应切换倒计时

标签 jquery css

我正在开发一个问答游戏,我希望每个问题(总共 5 个问题)在 20 秒后自动更改。请提供html代码,并提供每个问题的20秒倒计时代码。

**

How the countdown can be toggled (paused/resumed on click) ?

**

最佳答案

试试这个:

<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        .question {
            display: none;
        }
        .count {
            position: absolute;
            top: 100px;
        }
    </style>
</head>
    <body>
        <h1 class="question">I am Question 1</h1>
         <h1 class="question">I am Question 2</h1>
         <h1 class="question">I am Question 3</h1>
         <h1 class="question">I am Question 4</h1>
         <h1 class="question">I am Question 5</h1>
        <h3 class="count">CountDown : 19 </h3>
       <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      
        <script>
          
$(document).ready(function(){
    
    var total = $(".question").length;
    var cur = 1;
    var cou = 19;
    
    $(".question").eq(0).show().delay(18000).hide(2000);
    
    var timer = setInterval(function(){
        
        fun();
        
    },20000)
    
    function fun(){
        
        $(".question").eq(cur).show().delay(18000).hide(2000);
        
        cur += 1;
        
        if(cur >  total) {
            
            alert("done");
            clearInterval(timer);
            clearInterval(countTimer);
        }
    }
    
    var countTimer = setInterval(function(){
      
      cou -= 1;
    
    $(".count").text("CountDown : " + cou);
    
    
    if(cou === 0)
        cou = 20;
    
    
    
},1000);

    
})
            
        </script>
    </body>
</html>

关于jquery - 在倒计时的特定时间后更改问题以及是否应切换倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39547997/

相关文章:

html - 在 Bootstrap 中创建 App Store 按钮

javascript - 全屏图像,下面有一排小图像

遗留应用程序中的 requirejs 重新定义了 jQuery

javascript - 数据正确返回但无法正常显示返回的数据?

css - 防止正文滚动但允许覆盖滚动

html - cake.generic.css : Can't decrease the width of a table inside a division 的 CSS 问题

javascript - 将 uib Modal Content 从模态内容移到页面顶部

jquery - safari 5.1.7 无法对齐输入占位符文本中心

javascript - 通过来自动态输入的 ajax 请求发送数据

javascript - 带有多个复选框的 HTML 表格过滤器