# About the Snow Script

**URL:** <https://forum.kirupa.com/t/about-the-snow-script/663564>\
**Category:** programming\
**Created:** [December 9, 2023, 12:58pm UTC](https://forum.kirupa.com/t/about-the-snow-script/663564 "2023-12-09T12:58:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Izawebmaster](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/izawebmaster/32/24744_2.png) [@Izawebmaster](https://forum.kirupa.com/u/Izawebmaster)\
**Post date:** [December 9, 2023, 12:58pm UTC](https://forum.kirupa.com/t/about-the-snow-script/663564/1 "2023-12-09T12:58:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [December 9, 2023, 6:09pm UTC](https://forum.kirupa.com/t/about-the-snow-script/663564/2 "2023-12-09T18:09:58Z")

</div>

Do the snowflakes come back after a bit, or are they always permanently less in quantity?

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [December 9, 2023, 6:47pm UTC](https://forum.kirupa.com/t/about-the-snow-script/663564/3 "2023-12-09T18:47:16Z")

</div>

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](https://www.youtube.com/watch?v=dz3iLDFbXOE).

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [December 9, 2023, 6:53pm UTC](https://forum.kirupa.com/t/about-the-snow-script/663564/4 "2023-12-09T18:53:32Z")

</div>

(Or if there’s no API, checking the time between rAF calls would be functionally equivalent for the most part for big delays.)

---

<div class="post-metadata">

**Author:** ![Izawebmaster](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/izawebmaster/32/24744_2.png) [@Izawebmaster](https://forum.kirupa.com/u/Izawebmaster)\
**Post date:** [December 9, 2023, 7:08pm UTC](https://forum.kirupa.com/t/about-the-snow-script/663564/5 "2023-12-09T19:08:43Z")

</div>

After a while there is no snowflake left

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [December 9, 2023, 7:25pm UTC](https://forum.kirupa.com/t/about-the-snow-script/663564/6 "2023-12-09T19:25:09Z")

</div>

A modification to the first few lines of `moveSnowflakes` would probably fix it:

```javascript
    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.

---

<div class="post-metadata">

**Author:** ![Izawebmaster](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/izawebmaster/32/24744_2.png) [@Izawebmaster](https://forum.kirupa.com/u/Izawebmaster)\
**Post date:** [December 10, 2023, 5:48am UTC](https://forum.kirupa.com/t/about-the-snow-script/663564/7 "2023-12-10T05:48:29Z")

</div>

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  
}
