3 ms·
The timeLeft -= 1000 approach is not the best one because setTimeout doesn't guarantee when the next tick is gonna happen. Just open the JS console and type:
by rochoa 14y ago
The timeLeft -= 1000 approach is not the best one because setTimeout doesn't guarantee when the next tick is gonna happen.
Just open the JS console and type:
for (var i = 0; i < 1e7; i++) {}
You will block the JS execution and your next tick will happen when the loop finishes. Using new Date().getTime() should do the job.
Edited for formatting.
- ajanuary 14y agoScrolling in iOS also stops setTimeout being called.
- juliangruber 14y agoI fixed that, thanks :)