I am trying to write a custom increment function for FlipClock JS. So that every 5-20 seconds the counter is incremented by 1. I tried surrounding the clock.increment code with a settimeout function, I could not get it to work as I do not know where it is actually looping. I then looked at the flipclock.js file itself I managed to make it go up in 0.5, 0.25 and I can also make it delay start, but I cannot figure out how to make it increment every so often. I thought I could just add something like delay(500) before the clock.increment but I don't think that's where the loop is.
If you need any more info, ask.
Thanks!
I couldn't find a CDN that hosted flipclock so here is the code.
The counter increments +1 every 5 to 20 seconds.
<html>
<head>
<link rel="stylesheet" href="../compiled/flipclock.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="../compiled/flipclock.js"></script>
</head>
<body>
<div class="clock" style="margin:2em;"></div>
<div class="message"></div>
<script type="text/javascript">
var clock;
var nextDoubleJump;
var internalCounter;
$(document).ready(function() {
internalCounter = 0;
nextDoubleJump = getRandomIntInclusive(5, 20);
console.log('Next jump value: ' + nextDoubleJump);
clock = $('.clock').FlipClock({
clockFace: 'Counter',
autoStart: false,
});
setInterval(function(){
internalCounter += 1;
console.log(internalCounter);
if(internalCounter == nextDoubleJump) {
clock.increment();
nextDoubleJump = getRandomIntInclusive(5, 20) + internalCounter;
console.log('Next jump value: ' + nextDoubleJump);
}
}, 1000);
});
function getRandomIntInclusive(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
</script>
</body>
</html>