2

I am trying to create a pulsating circular background with smooth edges. For the circle with smooth edges I am using this CSS code:

background: radial-gradient(black, black, transparent, transparent);

Using my code below works well to animate the background-color. However, as soon as I replace the background-color with this radial-gradient background the animation jumps and is no longer smooth. The behavior is consistent over multiple Browsers. This is a minimal working example of the issue I am having:

.global {
  background: lightskyblue;
}

.silver {
  // background: radial-gradient(black, black, transparent, transparent);
  animation: pulse 3s infinite;
}

@keyframes pulse {
  0%,
  100% {
    // background-color: black;
    background: radial-gradient(black, transparent, transparent, transparent);
  }
  50% {
    // background-color: white;
    background: radial-gradient(black, black, transparent, transparent);
  }
}
<body class="global">
  <img src="pngwave.png" alt="test" class="silver" />
</body>

I have found this Stackoverflow question which is similar but did not help me solve my problem.

1 Answer 1

3

You need to animate the background-size

.box {
  width: 200px;
  height: 200px;
  background: radial-gradient(farthest-side,black, transparent) center no-repeat;
  animation:pulse 2s linear infinite alternate;
}
@keyframes pulse{
  from {
    background-size:50% 50%;
  }
  to {
    background-size:100% 100%;
  }
}
<div class="box"></div>

Sign up to request clarification or add additional context in comments.

2 Comments

Actually I have another very related problem: Is it possible to do this with the actual background-color? The reason is that the element I am working with has a background image and background replaces the background-image while background-color works well with a background-image.
@JRsz use multiple background: jsfiddle.net/xr3h52od

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.