How to use CSS filter & CSS Animation on images

Today I learned something very very very useful for web design:
How to use CSS filters on images and how to animate them !

Why is it better than JavaScript, JQuery, animated .giff or else? Because it takes fewer resources and thus renders faster. Moreover JavaScript is some times deactivated on browsers.

Mona LisaMona LisaMona LisaMona LisaMona LisaMona LisaMona LisaMona LisaMona Lisa

 

Above is the results you can achieve. It is just like photoshopped, but better. And yes, you’ll learn how to use it in CSS animations as well.

The HTML

The CSS

Note that you’ll need vendor prefixes to get good browser support where -moz is firefox, -o opera and so on…

See Browser compatibility @MDN

I’m sure that you can figure many ways to use it! One i.e. would be to use it with CSS Animations like so:

Animating Background jpg IMG

The CSS

So basically you start by setting the animation: changeColor 5s infinite; on an element while changeColor will be the name of the animation. You can replace it with whatever you want. 5s is the animation speed or duration. By infinite you set the repeat to infinite (write an integer instead to change it).

Then you create the animation with @keyframes + the name of your animation. Here it was changeColor as set above. Lastly, you set key-frames. So 0% is the very beginning of the 5s animation while 100% is the end => 5 seconds.

CSS Animations are awesome and I use them a lot to create smooth and lightweight transitions! Now it’s your turn, I bet you can come up with something even better.

Leave a Reply