U
U
UnRealName2015-10-23 11:26:51
css
UnRealName, 2015-10-23 11:26:51

How can I change the color of an image on hover?

Please, tell me, sometimes I come across such a trick on sites: when you hover over a gray image, it is colored.

Here is the last example with sponsors: https://www.cybermarketing.ru/conf2015#sponsor

Once I did the opposite thing, with the help of opacity I changed the appearance of a color image. But in this case, most likely scripts are used.

I will be glad to ready-made templates.

Answer the question

In order to leave comments, you need to log in

8 answer(s)
T
twobomb, 2015-10-23
@UnRealName

https://jsfiddle.net/7w3kfrtt/

R
Radiks Alijevs, 2015-10-23
@dedalik

You can use css3, the filter property, with which you can manipulate the color of the image.
Here are examples of css3 image filters
All demos are here
Browsers that support css3 filter , unfortunately IE is stupid as always.
If you need only from black and white to color, here is a good article with sources, and here is a demo, support for IE 7+

O
Oleg, 2015-10-23
@Screpka

img {
filter: greyscale(100%);
}
img:hover {
filter: grayscale(0);
}
Doesn't work in all browsers, so you'll have to add -moz- -ms- -webkit- -o-

D
Defman21, 2015-10-23
@Defman21

CSS: filter, no?
UPD: I looked at the site. They just have one big image with a color and gray logo. https://www.cybermarketing.ru/images/conf2015/cm-s...
With this approach, you just need to change the background shift.

A
AlikDex, 2015-10-23
@AlikDex

Open the code and take a look. In short, the above example uses a background offset on the hover event.
The image itself is a sprite.

U
UnRealName, 2015-10-23
@UnRealName

I realized that they have everything done in one picture) Then it's not so interesting)
I'm more interested in how to make a finished color image black and white using css or js, but return it to its original color on hover.
UPD
Here is a slightly different solution: registratura.ru/contacts/sotrudniki

N
Nikita K., 2015-10-23
@bonilka

You can also use canvas
www.html5canvastutorials.com/advanced/html5-canvas...

D
Dmitry Kuznetsov, 2015-10-23
@dima9595

A lot of people have already written, but still I will answer:
1. Put the picture in a class, for example, in .image-gray. And we add a filter to this class in CSS.
2. On hover (:hover) - remove this filter.
Profit)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question