-4

Does anyone know how to make black and white images animate to color when you hover over them. This would be like digitally revealing a painting or doing a text fill animation if that makes sense. It's an idea I have for a project.

5
  • 1
    Welcome to Stack Overflow!, Please take the tour, and read how to ask, an On Topic question, then look at the Question Check list, the perfect question and how to create a Minimal, Complete and Verifiable Example Commented Feb 21, 2024 at 0:16
  • For future reference, "I haven't tried anything yet" is a sure fire way to not get any answers. Commented Feb 21, 2024 at 0:34
  • One way to try things is to get yourself a JSFiddle or CodePen account. They make it very easy to try out code. jsfiddle.net codepen.io Commented Feb 21, 2024 at 0:36
  • 2
    To those who have closed this question as a duplicate, I believe the OP was asking not about simply switching between B+W and color, but animating the switch. In which case a better resource is this article. Commented Feb 21, 2024 at 0:48
  • 1
    Voting to reopen as the post given as a duplicate does not cover animation (as pointed out by @BrettDonald) and it contains some fairly (in 2024) awful ways round the b/w to color problem. The answer here from @artlung answers the question well and will be useful to future readers. Commented Feb 21, 2024 at 8:12

1 Answer 1

2

Look into the filter function saturate which gives the ability to control the saturation of the colors on an element. Along with a transition you get the effect of animation.

a.colorful {
  display: inline-block;
  color: #fff;
  text-align: center;
  background-image: linear-gradient(
   90deg,
   red,
   orange,
   yellow,
   green,
   blue,
   indigo,
   violet
  );
  width: 50vw;
  padding: 2rem;
  border-width: 0;
  font-family: sans-serif;
  font-size: 2rem;
  text-shadow: 1px 1px 2px #000;
  filter: saturate(0);
  transition: all 0.2s;
}
a.colorful:hover {
  filter: saturate(1);
  border: none;
}
<a class="colorful">Hello!</a>

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

2 Comments

The OP was asking about animating the switch.
@BrettDonald It is animated, but only for 0.2s ...

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.