The snow script works nice on my page but when I go to another tab in chrome and later come back to the tab of my page the script acts strange, lesser en slower flakes
Do the snowflakes come back after a bit, or are they always permanently less in quantity?
Oh, I see what @Izawebmaster is saying about revisiting a tab. I think requestAnimationFrame
or some similar API is throttled for background tabs. And yeah they do come back.
Presumably there’s a JavaScript / DOM API these days to detect that sort of throttling, as you could do in ActionScript back in the day.
(Or if there’s no API, checking the time between rAF calls would be functionally equivalent for the most part for big delays.)
After a while there is no snowflake left
A modification to the first few lines of moveSnowflakes
would probably fix it:
let tbtU = 17 // milliseconds
function moveSnowflakes(currentTime) {
tbtU = (tbtU + (currentTime - previousTime)) / 2
delta = (currentTime - previousTime) / frame_interval
previousTime = currentTime
console.log(tbtU)
if (performance.now() > 10000 && tbtU > 70) {
console.log("pause")
requestAnimationFrame(moveSnowflakes)
return
}
It’s basically just a check to say… hey if we’re not hitting our frame budget at all (probably due to unfocused tab throttling), stop updating the snowflake positions.
Yes! That worked.
Thank you so much for your help.
The MoveSnowflakes section I now use:
let tbtU = 17 // milliseconds
function moveSnowflakes(currentTime) {
tbtU = (tbtU + (currentTime - previousTime)) / 2
delta = (currentTime - previousTime) / frame_interval
previousTime = currentTime
console.log(tbtU)
if (performance.now() > 10000 && tbtU > 70) {
console.log(“pause”)
requestAnimationFrame(moveSnowflakes)
return
}