Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Multiple Transitions of the Same Element

I am trying to make a dropdown effect for one of my background images. I was able to do it using css3 but it's not complete.

The effect is supposed to be a curtain that drops down then sort of bounces back up a little. The problem with css3 is that I don't know how to do to transitions on the same property because the last one overrides the previous ones.

Here's my code:

ul#nav li a {
  /* ADDS THE DROPDOWN CURTAIN TO THE LINKS BUT HIDDEN OFF SCREEN */
  background: url(images/drape2.png) 0px -149px no-repeat;
  /* CSS3 transitions */         
  -moz-transition: all 200ms ease-in-out;         
  -webkit-transition: all 200ms ease-in-out;         
} 

ul#nav li a:hover {            
  /* Action to do when user hovers over links */                          
  background-position: 0px 0px; /* make drape appear, POOF! */             
  background-position: 0px -10px; /* make drape appear, POOF! */             
}            

Any help would be much appreciated.

like image 487
Free Lancer Avatar asked Nov 26 '11 02:11

Free Lancer


2 Answers

Using cubic-bezier like this:

cubic-bezier(0, 0.35, .5, 1.3)

You can make an animation go backwards—or bounce a little.

Demo (Only works in Firefox)

Source

Edit: I also made you a Webkit only option, I don't know how compatible these two techniques are. It may also work in Firefox with the -moz browser prefixes, but I haven't tested it. This one uses keyframe animation as opposed to transitions.

like image 24
bookcasey Avatar answered Sep 30 '22 13:09

bookcasey


You'll want to chain them with commas instead of a new line

For instance:

background-color 500ms linear, color 500ms linear;
like image 131
Gregg B Avatar answered Sep 30 '22 14:09

Gregg B