Home > Web Front-end > CSS Tutorial > How to Keep an Image Centered During CSS3 Scaling Animations?

How to Keep an Image Centered During CSS3 Scaling Animations?

DDD
Release: 2024-12-17 15:45:11
Original
966 people have browsed it

How to Keep an Image Centered During CSS3 Scaling Animations?

How to maintain a centered image during animation?

In a situation like the one shown in the fiddle you provided, where a CSS3 animation scales an element in the absolute position of another element centered in the center, you might encounter a misalignment of the element during animation. Specifically, it might appear off-center, as demonstrated by the red squares in the fiddle.

To remedy this, we can modify the transform-origin property. The issue arises when the new transformation (within the animation) overrides the original one. In this case, the original transformation serves to maintain the element's centered alignment.

To circumvent this problem, we must combine the transformations within the same transform property, ensuring the correct order. The following code illustrates the corrected approach:

@keyframes ripple_large {
  0% {
    transform: translate(-50%, -50%) scale(1);
  }
  75% {
    transform: translate(-50%, -50%) scale(3);
    opacity: 0.4;
  }
  100% {
    transform: translate(-50%, -50%) scale(4);
    opacity: 0;
  }
}
Copy after login

The above is the detailed content of How to Keep an Image Centered During CSS3 Scaling Animations?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template