Home > Web Front-end > CSS Tutorial > How Can I Create Smooth Fade-In Text Animations on Page Load Using CSS, jQuery, or Both?

How Can I Create Smooth Fade-In Text Animations on Page Load Using CSS, jQuery, or Both?

Linda Hamilton
Release: 2024-12-21 02:17:13
Original
371 people have browsed it

How Can I Create Smooth Fade-In Text Animations on Page Load Using CSS, jQuery, or Both?

Creating Fade-In Animations on Page Load with CSS

The Problem: Enhancing website aesthetics by creating a text paragraph that fades in smoothly as the page loads.

Solution:

Using CSS Animations

#test p {
  opacity: 0;
  margin-top: 25px;
  font-size: 21px;
  text-align: center;

  animation: fadein 2s;
  animation-fill-mode: forwards;
}

@keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
Copy after login
  • Implement this solution with CSS animations, ensuring compatibility with all modern browsers.

Using jQuery

$("#test p").addClass("load");
Copy after login
#test p {
  opacity: 0;
  margin-top: 25px;
  font-size: 21px;
  text-align: center;

  transition: opacity 2s ease-in;
}

#test p.load {
  opacity: 1;
}
Copy after login
  • Utilize jQuery to add a class upon page load that triggers the fade-in via CSS transitions.

Emulating DotMail's Approach

$("#test p").delay(1000).animate({ opacity: 1 }, 700);
Copy after login
  • Mimic the fade-in effect employed by DotMail through a combination of jQuery delay and animation.

Browser Compatibility:

  • CSS Animations: Modern browsers and Internet Explorer 10
  • CSS Transitions: Modern browsers and Internet Explorer 10
  • jQuery (Required for Methods 2 and 3): Varies based on version, but generally cross-compatible with older browsers.

Choose the method that best aligns with your browser support requirements and desired level of animation customization.

The above is the detailed content of How Can I Create Smooth Fade-In Text Animations on Page Load Using CSS, jQuery, or Both?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template