当剩余时间等于 X 时触发事件

Triger event whenever remaining time equals X

我有一个正在运行的 js 倒计时。当剩余时间变少时,我也有倒计时闪烁。

我想生成一组键号(什么时候闪)

我有这个

currenttime = Date.now() / 1000 | 0
targettime = currenttime + 20
flashfrequency = 3
flashenable = 10
setInterval(function() {
  currenttime = Date.now() / 1000 | 0
  remainingtime = targettime - currenttime
  if (remainingtime < 0)
    remainingtime = 0
  if ((remainingtime % flashfrequency === 0) && (remainingtime < flashenable))
    flash = "body {background-color:black; color:white;}"

  else
    flash = "body {background-color:white; color:black;}"

  document.getElementById('timehere').innerHTML = remainingtime;
  document.getElementById('flashhere').innerHTML = flash;

}, 50);
<head>
  <style id="flashhere" type="text/css"></style>

  <body>
    <table>
      <tr>
        <td id="timehere">hello</td>
      </tr>
    </table>
  </body>

我想用

var flashfrequency=10 //as time when to flash 

var flashenable=40 //as maximum remaining time to flash

我不知道从哪里开始从 flashfrequency 和 flashenable 生成值

用于生成从 0 到 (0,10,20...) flashenable (...30,40) 的每个 flashfrequency 第数的列表的代码。

if 语句将剩余时间与生成的列表 (0,10,20,30,40) 进行比较

尝试替换为 % Remainder operator

if (remainingtime % 10 === 0)

for || OR 运算符

if ((remainingtime == 0) 
    || (remainingtime == 10) 
    || (remainingtime == 20) 
    || (remainingtime == 30) 
    || (remainingtime == 40))

处于if条件

currenttime = Date.now() / 1000 | 0
targettime = currenttime + 50

setInterval(function() {
  currenttime = Date.now() / 1000 | 0
  remainingtime = targettime - currenttime
  if (remainingtime < 0)
    remainingtime=0
  if (remainingtime % 10 === 0)
    flash = "body {background-color:black; color:white;}"

  else
    flash = "body {background-color:white; color:black;}"

  document.getElementById('timehere').innerHTML = remainingtime;
  document.getElementById('flashhere').innerHTML = flash;

}, 50);
<head>
  <style id="flashhere" type="text/css"></style>

  <body>
    <table>
      <tr>
        <td id="timehere">hello</td>
      </tr>
    </table>
  </body>