我有一个正在运行的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);
&#13;
<head>
<style id="flashhere" type="text/css"></style>
<body>
<table>
<tr>
<td id="timehere">hello</td>
</tr>
</table>
</body>
&#13;
我想用
var flashfrequency=10 //as time when to flash
和
var flashenable=40 //as maximum remaining time to flash
我不知道从flashfrequency和flashhenable
开始生成值的位置生成每个flash频率列表的代码,从0到0(0,10,20 ......)闪烁(... 30,40)。
if语句将剩余时间与生成列表(0,10,20,30,40)进行比较
答案 0 :(得分:1)
if (remainingtime % 10 === 0)
用于||
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);
&#13;
<head>
<style id="flashhere" type="text/css"></style>
<body>
<table>
<tr>
<td id="timehere">hello</td>
</tr>
</table>
</body>
&#13;