Maybe you can make use of CSS3 Animations, using one for sliding in and another one for sliding out:
@keyframes overlay-in {
from {
left: -999px;
}
to {
left: 0;
}
}
@keyframes overlay-out {
from {
left: 0;
}
to {
left: 999px;
}
}
Now you can apply the overlay-in
animation on :hover
and the other one on the normal element definition:
.box .overlay {
/* other definitions ... */
animation-name: overlay-out;
animation-duration: 1000ms;
animation-fill-mode: none;
}
.box:hover .overlay {
animation-name: overlay-in;
animation-duration: 600ms;
animation-fill-mode: forwards;
}
But there is one problem with this: The slide-out animation will play once on page load. I can't figure out a way to prevent this without a tiny JavaScript, adding a class to the overlay on the first mouseout
event. I've done it this way in a JSFiddle.
But of course, as soon as you require JavaScript, you could also have used simple transitions. But this method works even without JavaScript if you can live with the animation playing on page load.