Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different CSS transition-delays for hover and mouseout?

Is it possible to use CSS3 transitions with a different delay switching between "states"? For example, I'm trying to make an element immediately higher upon hover then on 'mouseout' to wait a second before sliding back to the element's initial height.

Demo page: jsfiddle.net/RTj9K (hover black box in top-right corner)

CSS: #bar { transition:.4s ease-out 0, 1s; }

I thought the timings on the end related to delay but it doesn't seem to be working the way I'd imagined.

like image 471
Marcel Avatar asked May 07 '11 12:05

Marcel


People also ask

Is CSS transition only for hover?

But transitions are not just limited to use with :hover . You can animate CSS properties, thus use CSS transitions without hover. This is done via transitions using some other CSS techniques, a number of which I've outlined below.

Which delay CSS property is used for transition effect?

The transition-delay property specifies when the transition effect will start. The transition-delay value is defined in seconds (s) or milliseconds (ms).

How do you delay the hover effect?

You can use transitions to delay the :hover effect you want, if the effect is CSS-based. this will delay applying the the hover effects ( background-color in this case) for one second.


2 Answers

If you want different CSS transition delays on hover and mouseout, you have to set them using the relevant selectors. In the example below, when an element is hovered, the initial delay on hover is 0 but on mouseout the transition is delayed by 1s.

/* These transition properties apply on "mouseout" */ #bar { transition:height .5s ease-out 1s; }   /* These transition properties apply on hover */ #bar:hover { transition:height .5s ease-out 0s; } 

You can find the full CSS in my question's updated demo below. I've used the shorthand transition property, the order of the values are:

transition:<property> <duration> <timing-function> <delay>; 

Answer Demo: http://jsbin.com/lecuna/edit?html,css,output

like image 184
Marcel Avatar answered Oct 08 '22 15:10

Marcel


Here is a simplified JSFiddle example. Basically you need the transition-delay property:

#transform {     height:40px;     width:40px;     background-color:black;     transition: .4s ease-out;      transition-delay: 2s;     /*or shorthand: transition: .4s ease-out 2s;*/ }  #transform:hover {     transition: .4s ease-out;      width:400px; } 
like image 40
Dan Manastireanu Avatar answered Oct 08 '22 15:10

Dan Manastireanu