-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
animationstart hook not effective if lazy loaded #260
Comments
Turns out this is also a problem when we fetch remote stylesheets. The stylesheets themselves are already loaded, but the |
We can use |
I tested this out and that works except for the condition of them running. Most of them have a default duration of |
Maybe we could temporarily change the fill mode to |
An alternate option would be to have a very small snippet that is run synchronously which simply collects a list of started animations and then passes them in to be set up by the polyfill after its loaded. |
The syncronous snippet might be hard, we can't collect it immediately if say a framework like React mounts or re-renders and that triggers an animation after the snippet but before the polyfill is loaded (or remote stylesheets fetched and parsed). The |
Yes! This should avoid any visible side effects. Finished animations will remain finished whereas calling play restarts them. |
This wouldn't be a problem, you'd simply keep a list of animations to check later to see if they should be scroll driven, e.g. let startedAnimations = new Set();
window.addEventListener('animationstart', (evt) => {
evt.target.getAnimations().filter(anim => anim.animationName === evt.animationName).forEach(anim => {
startAnimations.add(anim);
});
}); Then after the polyfill loads you'd process each of startedAnimations as if they had an animationstart event, i.e. calling the code here: https://github.com/flackr/scroll-timeline/blob/master/src/scroll-timeline-css.js#L174 |
Let me give that a shot! |
It did seem to work, actually. Was also running into another issue where the syntax parser had invalid syntax so stopped processing all animations. That's probably correct, but challenging in a production scenario.
|
We are asynchronously loading, so the start event has already happened when the polyfill loads in Safari.
I tried various workarounds like waiting for the polyfill to load and switching from play state paused to running.. Perhaps completely not applying until then is an option, but that's tricky for authors.
My current workaround is to apply a data attribute to each element and once loaded query them all and call play on the animations. That does seem to work.
The text was updated successfully, but these errors were encountered: