4 ms·
I'd guess there's a race condition that causes the eyes to end up closed, because the 'delay' can sometimes be less than 150 and `blink` gets called while it's
by emurlin 4y ago
I'd guess there's a race condition that causes the eyes to end up closed, because the 'delay' can sometimes be less than 150 and `blink` gets called while it's already executing (so `src` ends up being the blink version). A simple fix would be adding `await` to `blink()` if that's the case!
BTW, I made a vanilla JS version for fun, without jQuery or promises (untested)
function blinktimer() {
var avatar = document.querySelector(" .avatar ");
var srcBlink = '/images/dadi-avatar_blink.png';
var blink = function() {
console.log("BLINK!");
var srcOpen = avatar.src;
avatar.src = srcBlink;
setTimeout(function() {
avatar.src = srcOpen;
var delay = (Math.random() * 11000) | 0;
setTimeout(blink, delay);
}, 150);
}
var delay = (Math.random() * 11000) | 0;
setTimeout(blink, delay);
}
- justusthane 4y agoAh! That makes sense, thank you! I'd say it's more of an unintended feature than a bug :)