如何使用HTML,CSS或JavaScript创建循环倒数计时器?

Aru*_*raj 19 html javascript css timer

目前,我正在开展一个问答游戏,对于每个问题,我希望放置一个倒数计时器.我有一些插件,但我希望自己可以创建它.我想要创建的内容看起来像下图中的那个.你能告诉我怎么做吗?

有没有办法将边框分配到最多只有指定百分比的周长,这样我就可以先给出一个边框,然后随着每一个进展,我可以继续减少/增加它以便我得到它以完美的方式.

我希望创建的计时器应该看起来像这样(希望你了解它的蓝色边框每秒会增加):

在此输入图像描述

Tur*_*nip 55

这是我刚才玩的东西.它使用SVG,css过渡和javascript的组合.你应该能够撕开它并用作起点......

/**
* The setTimeout({},0) is a workaround for what appears to be a bug in StackSnippets.
* It should not be required. See JSFiddle version.
*/

setTimeout(function() { 

  var time = 10; /* how long the timer will run (seconds) */
  var initialOffset = '440';
  var i = 1

  /* Need initial run as interval hasn't yet occured... */
  $('.circle_animation').css('stroke-dashoffset', initialOffset-(1*(initialOffset/time)));

  var interval = setInterval(function() {
      $('h2').text(i);
      if (i == time) {  	
        clearInterval(interval);
        return;
      }
      $('.circle_animation').css('stroke-dashoffset', initialOffset-((i+1)*(initialOffset/time)));
      i++;  
  }, 1000);

}, 0)
Run Code Online (Sandbox Code Playgroud)
.item {
    position: relative;
    float: left;
}

.item h2 {
    text-align:center;
    position: absolute;
    line-height: 125px;
    width: 100%;
}

svg {
   -webkit-transform: rotate(-90deg);
    transform: rotate(-90deg);
}

.circle_animation {
  stroke-dasharray: 440; /* this value is the pixel circumference of the circle */
  stroke-dashoffset: 440;
  transition: all 1s linear;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="item html">
    <h2>0</h2>
    <svg width="160" height="160" xmlns="http://www.w3.org/2000/svg">
     <g>
      <title>Layer 1</title>
      <circle id="circle" class="circle_animation" r="69.85699" cy="81" cx="81" stroke-width="8" stroke="#6fdb6f" fill="none"/>
     </g>
    </svg>
</div>
Run Code Online (Sandbox Code Playgroud)

JSFiddle版本