void element.offsetWidth; is a curious line of code that would seem to do nothing, but is required for a CSS animation to work. What does this line do and why is it needed?
If the entire line is commented out, the animation happens once but does not repeat. (It still works if the void is removed.)
The full code/demo is live here; I tried to copy the relevant excerpts below:
script.js:
beatIndicator = document.getElementById("beatIndicator"),
...
// Happens every time a beat starts:
beatIndicator.classList.remove("anim");
void beatIndicator.offsetWidth; // Why is this line needed?
beatIndicator.classList.add("anim");
example-advanced.html
<span style="display: none;" id="beatIndicator" class="pulse"></span>
<style>
.pulse {
width: 40px;
height: 40px;
border-radius: 50%;
background: #f44336;
z-index: 3;
left: -18px;
display: inline-block;
vertical-align: middle;
margin-left: 10px;
}
@keyframes pulse-anim {
from {
box-shadow: rgba(244, 67, 54, 1) 0px 0px 0px 0px;
}
to {
box-shadow: rgba(244, 67, 54, 0) 0px 0px 0px 14px;
}
}
.pulse.anim {
animation: pulse-anim;
}
</style>