Skip to content
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

Explore requestAnimationFrame and Web Animation API #4

Open
abdmmar opened this issue Dec 24, 2021 · 0 comments
Open

Explore requestAnimationFrame and Web Animation API #4

abdmmar opened this issue Dec 24, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@abdmmar
Copy link
Owner

abdmmar commented Dec 24, 2021

Why

  • Smooth animation. 60fps

Current Progress

Use Web Animation API:

const toaster = document.querySelector('wc-toast');
const toastContainer = toaster.shadowRoot.children[1];

const first = toastContainer.offsetHeight;

toaster.appendChild(toastItem);

const last = toastContainer.offsetHeight;

const invert = last - first;

const animation = toaster.animate(
  [{ transform: `translateY(${invert}px)` }, { transform: `translateY(0)` }],
  {
    duration: 300,
    easing: 'ease-out'
  }
);

animation.startTime = document.timeline.currentTime

Probably will use requestAnimationFrame for better support and keep the wc-toast size small (no need for polyfill)

Blocker

  • First toast run animation perfectly smooth, but when another toast is added to the container, it bounces and makes the distracting animation
  • When the toast container changes the position to the bottom of the page (default is at the top) or changes it back to the default, animation doesn't run at all (except CSS animation).

References

@abdmmar abdmmar added the enhancement New feature or request label Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant