根据用户输入更改倒数速度

时间:2019-01-24 11:27:59

标签: php html timer countdown

比方说,默认计时器现在是每秒减少1秒(默认值),问题在于如何根据用户输入(用户输入3,(系统倒数每秒减少3))更改倒数速度

https://jsfiddle.net/9q8wLyhs/,这是示例代码

<link href="https://fonts.googleapis.com/css?family=Yantramanav:400,500,700,900" rel="stylesheet">
<!-- Display the countdown timer in an element -->
<p id="demo" style="background-image: -moz-linear-gradient(top,#b8b0af 0%,#f2ecea 100%);
background-image: -webkit-linear-gradient(top,#b8b0af 0%,#f2ecea 100%);
background-image: -o-linear-gradient(top,#b8b0af 0%,#f2ecea 100%);
background-image: -ms-linear-gradient(top,#b8b0af 0%,#f2ecea 100%);
background-image: linear-gradient(top,#b8b0af 0%,#f2ecea 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
position:relative;font-size:1.2em;font-family: 'Yantramanav', sans-serif;font-weight:900;text-align: center;

"></p>

<script>
// Set the date we're counting down to
var countDownDate = new Date("May 5, 2019 12:00:00").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get todays date and time
  var now = new Date().getTime();

  // Find the distance between now an the count down date
  var distance = countDownDate - now;

  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);

  // Display the result in the element with id="demo"
  document.getElementById("demo").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";

  // If the count down is finished, write some text 
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);
</script>

(用户输入3,(系统倒数每秒减少3)

0 个答案:

没有答案