Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 one-way transition?

Tags:

html

css

Using CSS3 transitions, it's possible to have a 'smooth up' and 'smooth down' effect to whatever property.

Can I have it setup to have only a 'smooth down' effect? I'd like the solution to be in CSS only, avoiding JavaScript if possible.

Logic flow:

  • User clicks element
  • Transition takes 0.5s to change background color from white to black
  • User lets go of the mouse left button
  • Transition takes 0.5s to change background color from black to white

What I want:

  • User clicks element
  • Transition takes 0s to change
  • User lets go of mouse button
  • Transition takes 0.5s to change...

There's no 'transition-in' time, but there's a 'transition-out' time.

like image 578
Abhishek Avatar asked May 23 '11 02:05

Abhishek


People also ask

What is css3 transition?

CSS transitions provide a way to control animation speed when changing CSS properties. Instead of having property changes take effect immediately, you can cause the changes in a property to take place over a period of time.

How do you change the transition direction in CSS?

It works as follows: The overlay resting state is set to the right of the element using a margin (while the left is positioned to the left of the element). Upon hover, we set the margin to 0 without an animation. This allows the left animation to occur from the left side of the element.


1 Answers

I tried the following in the CSS3 Tryit Editor and it worked in Chrome (12.0.742.60 beta-m).

/* transition out, on mouseup, to white, 0.5s */  input  {    background:white;    -webkit-transition:background 0.5s;    -moz-transition:background 0.5s;    -ms-transition:background 0.5s;    -o-transition:background 0.5s;    transition:background 0.5s;  }    /* transition in, on click, to black, 0s */  input:active  {    background:black;    -webkit-transition:background 0s;    -moz-transition:background 0s;    -ms-transition:background 0s;    -o-transition:background 0s;    transition:background 0s;  }
<input type="button" value="click me to see the transition effect!">
like image 114
Matty K Avatar answered Sep 19 '22 06:09

Matty K