Home >Web Front-end >CSS Tutorial >Can CSS3 Keyframes Animate Elements on Page Load Without JavaScript?

Can CSS3 Keyframes Animate Elements on Page Load Without JavaScript?

Barbara Streisand
Barbara StreisandOriginal
2024-12-20 03:51:08352browse

Can CSS3 Keyframes Animate Elements on Page Load Without JavaScript?

CSS3 Transition Animation on Page Load: A Possibility

Can CSS3 transitions seamlessly animate elements on page load without JavaScript's aid?

Exploring the Options:

The quest for a solution led to several avenues:

  • CSS3 Transition-Delay: While effective in delaying hover effects, it's not applicable for page load.
  • CSS3 Keyframes: Capable of animating on load, but their sluggish nature hindered usability.
  • CSS3 Transition: Rapid execution, but no animation on page load.

The Revelation: Keyframes to the Rescue

Contrary to earlier beliefs, CSS3 Keyframes can indeed animate on page load.

Example: Sliding Menu

Observe a sleek navigation menu that glides into view using only CSS3:

@keyframes slideInFromLeft {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(0);
  }
}

header {
  animation: 1s ease-out 0s 1 slideInFromLeft;
  background: #333;
  padding: 30px;
}
<header>
  <a href="#">Home</a>
  <a href="#">About</a>
  <a href="#">Products</a>
  <a href="#">Contact</a>
</header>

The above is the detailed content of Can CSS3 Keyframes Animate Elements on Page Load Without JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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