简体   繁体   English

如何使计时器在特定时间后达到特定值?

[英]How to make timer reach certain value after specific amount of time?

Okay, i made a simple timer and i want to reach certain value after some time.好的,我做了一个简单的计时器,我想在一段时间后达到某个值。 Let's say it starts from 100 and it need to reach 300 in 2 mins and in the meantime it increments and decrements by 5 for example and keeps up to create the illusion that it's random and not just straightforward incrementation.假设它从 100 开始,需要在 2 分钟内达到 300,同时它以 5 为单位递增和递减,并不断创造出它是随机的,而不仅仅是简单的递增的错觉。 In the end it will reach 300 for the same time.最终它会同时达到300。 Similar to social blade real time subscribing.类似于社交刀片实时订阅。 It adds and removes certain amount of subscribers because people subscribe and unsubscribe but here it will reach the end value in 2 or 5 min.它添加和删除一定数量的订阅者,因为人们订阅和取消订阅,但在这里它将在 2 或 5 分钟内达到最终值。

 let count = 0; let end = 300; function increment() { if (count < end){ count++; }else if(count >= end) clearInterval(count); document.getElementById("num").innerHTML = count; } setInterval(increment, 1000);
 <html> <body> <h2 id="num"></h2> </body> </html>

I solved this problem.我解决了这个问题。

function subscribeEmu (sub, unsub, startCount, time);

takes 4 parameters:需要4个参数:
sub - number of subscribers sub - 订阅者数量
unsub - the number of unsubscribed unsub - 取消订阅的数量
counter start value计数器起始值
time - duration in milliseconds time - 以毫秒为单位的持续时间

here you can run.在这里你可以跑。

thank you!谢谢你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM