I want to fade between 'background-position' of a sprite image only with CSS. I found a lot o tutorials but I didn't found something simple like this:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>CSS3 - Fade between 'background-position' of a sprite image</title>
<style type="text/css">
div{
width: 120px;
height: 60px;
background-image: url('sprite.jpg');
background-repeat: no-repeat;
background-position: 0 0;
}
div:hover{
background-position: 0 -60px;
}
</style>
</head>
<body>
<div></div>
</html>
Thank you.
so basically, you need to perform two things upon
:hover
background-position
changefadein
effectCSS3 transition won't be useful in this case. You can use CSS3 animation property.
animation property accepts
name
of the animation and duration. Multiple animation names can be provided separated by comma.you need to define these animation names.They can be any string of your choice, but you need to define them. so consider this css:
see this fiddle, for complete browser supported animation
NOTE: it won't work in IE<9 for sure! and it might in IE9(not sure).
You can use
CSS3 Animation
with@keyframes
Example: http://jsfiddle.net/Y8W9S/
Of course, now you have to adjust the times and effect you want to implement.
Hope it's helps or point you in right direction.
Good luck.
Use like this:
And don't forget the optional vendor prefixes
Edit:
I've noticed you need fade. You try to similar solution like this:
I can't try this, coz' im from mobile.
I found the answer, thanks anyway.