【发布时间】:2015-12-26 01:38:20
【问题描述】:
我有一个正在运行的 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'th 数字的列表。
if 语句将剩余时间与生成的列表 (0,10,20,30,40) 进行比较
【问题讨论】:
-
可以创建stacksn-ps来演示吗?
-
@guest271314 制作了片段,并更改了 flash 变量以匹配 sn-p 示例
-
jsat stacksn-ps 不返回预期结果?需求是什么? -
试图从中获得更多可用性,写 if ((remainingtime = 0) || (remainingtime = 10) || (remaini............ ..(剩余时间 = 590) || (剩余时间 = 600))
标签: javascript logic