Home > Web Front-end > CSS Tutorial > How Can I Animate a Radial Gradient in CSS to Create a Shine Effect?

How Can I Animate a Radial Gradient in CSS to Create a Shine Effect?

Linda Hamilton
Release: 2024-12-06 08:49:10
Original
423 people have browsed it

How Can I Animate a Radial Gradient in CSS to Create a Shine Effect?

Animating a Radial Gradient using CSS

In the quest to create a radiant shine effect on a div box, the question is often raised regarding the most efficient and effective approach. Despite extensive research, there seems to be a lack of readily available resources addressing this specific need.

One common example found on the web resembles a simple overlay, falling short of the desired shine animation. However, by harnessing the CSS radial-gradient property and keyframe animations, achieving this visually engaging effect is entirely possible.

The Animation Process

The key to animating a radial gradient lies in establishing a gradient twice its intended size and setting the color stop values to half their usual counterparts. This preserves the visual appearance of the gradient while enabling smooth animation.

Implementing the Animation

To implement the shine animation, we can utilize the radial-gradient property to define the gradient and its position. By targeting this position within a keyframe animation, we can effortlessly shift the gradient from left to right, creating the illusion of a shimmering effect.

Code Example

#shine-div {
  height: 30vh;
  width: 60vw;
  margin: auto;
  border-radius: 10px;
  background: radial-gradient(farthest-corner at top, #FFFFFF 0%, #ffb3ff 4%, #ff33ff 12.25%, #800080 31.25%, #b300b3 50%)
    top right/200% 200%; /* Double the gradient size and adjust color-stop values */

  display: flex;
  justify-content: center;
  align-items: center;
  color: white;
  font-weight: bold;
  animation: colorChange 5s infinite alternate;
}

@keyframes colorChange {
  to {
    background-position: top left;
  }
}
Copy after login

Conclusion

Leveraging the power of CSS animations and gradient manipulation, it is entirely feasible to create a vibrant and captivating shine effect. By embracing this technique, developers can add an extra layer of visual appeal to their web applications.

The above is the detailed content of How Can I Animate a Radial Gradient in CSS to Create a Shine Effect?. 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