Dmitry2021-06-06 23:37:32
Dmitry, 2021-06-06 23:37:32

Anime.js How to animate the transition of an element to the center of the page, depending on the resolution?

There is an element that, when loading the page, should smoothly move from the left side of the screen to the center, depending on the resolution of the device. The parameter translateX: 0,does not accept percentages. It is necessary that this be implemented on the Anime.js plugin


Answer the question

In order to leave comments, you need to log in

1 answer(s)
RAX7, 2021-06-07

const logoEl = document.querySelector("#logo");
const logoRect = logoEl.getBoundingClientRect();

let logoAnim = anime({
  targets: logoEl,
  duration: 1500,
  translateX: (window.innerWidth - logoRect.width) / 2 - logoRect.x,
  translateY: (window.innerHeight - logoRect.height) / 2 - logoRect.y,
  easing: "easeInOutExpo"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question