I've got this timer for my game, and it works really well, but I want to develop it further by doing two things.
- Add a sound for the last 10 seconds (a subtle beep every second)
- Add a red background for the div that pulses each second for the last 10 seconds
I have tried to google about adding sound, but I can't really figure out how to do it. As for the div background I found a library called pulsate but it adds a border around the div, and what I really want is the background to flash, but I don't know how to do it manually.
I'm using the jquery.countdown cdn, as seen below. This is currently my jQuery for the countdown:
<script src="{% static 'js/jquery.countdown.min.js' %}"></script>
<script>
$(function timer() {
let currentDate = new Date();
let remainingTimeoutSeconds = {{ view.remaining_timeout_seconds|json }};
let milliseconds = Math.floor(remainingTimeoutSeconds * 1000);
$('.time-left').countdown(currentDate.valueOf() + milliseconds)
.on('update.countdown', function (event) {
// %-N is "Total count of minutes till the end, non-padded"
// %S is seconds left
let format = '%-N:%S';
$(this).html(event.strftime(format));
})
.on('finish.countdown', function (event) {
$('<input>').attr({
type: 'hidden',
name: 'timeout_happened',
value: '1'
}).appendTo('form');
$('#form').submit();
});
});
</script>
The last bit of code, on finish, simply submits the form with the values at the end of the timer. Less relevant to this problem.
call the above function at the end