support for Page Visibility API aka window blur/focus aka "I leave a tab in background"
See original GitHub issueI think this library would be great if it would also provide the “onLeave” behavior when the document becomes “invisible”, for instance you changed the tab on your browser, or you minimized the window and call back the “onEnter” when it comes back to visibility. there seems to be an API for that https://www.w3.org/TR/page-visibility/ but i’m pretty sure a way to detect that existed for a lot of time, back in the days i remember using jQuery(window).blur(fn)
and focus(fn)
a lot for this… it is really useful if you don’t want to leave tab running animation in background. even tho, nowadays, browser should schedule less timer events/animation frames when in background it’s still some useless interval/animations calls that can potentially be saved with this.
I imagine this can be an opt-in behavior because maybe this does not make sense for all usages of Waypoint, but I still think it should be part of the library for a unified way to handle onEnter/onLeave logics.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5
@jmeas that sounds absolutely fair, while there’s overlap in use, it’s definitely a bit outside the scope of this library. Thanks for taking the time. 👍
This is also a feature that I’d find useful, in my case I’m using
react-waypoint
to start/stop/replay some animations that occur as you scroll through different parts of a site. I’ve implemented my own window focus tracking to handle this, but it’d be convenient ifreact-waypoint
had this feature.I can see how this feature is a little unrelated to
react-waypoint
but there certainly is some overlap in use cases.Potentially it could be opt-in via a prop like
trackWindowFocus
.Anyway, thanks for a great library. 👌