Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delay a :hover effect in CSS?

Tags:

css

delay

hover

Is there a way to delay the :Hover event without using JavaScript? I know there is a way to delay animations, but I haven't seen anything on delaying the :hover event.

I'm building a son-of-suckerfish like menu. I'd like to simulate what hoverIntent does without adding the extra JS weight. I'd prefer to treat this as a progressive enhancement and not make JS a requirement for using the menu.

Example of menu markup:

<div>     <div>         <ul>             <li><a href="#">                 <ul>                     <li></li>                     <li></li>                 </ul>             </li>             <li>             <li>         </ul>     </div> </div> 

Here is the full demo: http://jsfiddle.net/aEgV3/

like image 510
Adam Youngers Avatar asked Dec 19 '11 19:12

Adam Youngers


People also ask

How do you delay effects in CSS?

CSS Demo: transition-delay A value of 0s (or 0ms ) will begin the transition effect immediately. A positive value will delay the start of the transition effect for the given length of time. A negative value will begin the transition effect immediately, and partway through the effect.

How do you delay animation in CSS?

CSS Animation Delay Syntax The CSS animation-delay property has the following syntax: animation-delay: [time] | initial | inherit; As you can see, there are three possible values: time, initial, and inherit. The first option is [time], which is the number of seconds or milliseconds before the animation starts.

How do you slow down transitions in CSS?

ease - specifies a transition effect with a slow start, then fast, then end slowly (this is default) linear - specifies a transition effect with the same speed from start to end. ease-in - specifies a transition effect with a slow start. ease-out - specifies a transition effect with a slow end.

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).


1 Answers

You can use transitions to delay the :hover effect you want, if the effect is CSS-based.

For example

div{     transition: 0s background-color; }  div:hover{     background-color:red;         transition-delay:1s; } 

this will delay applying the the hover effects (background-color in this case) for one second.


Demo of delay on both hover on and off:

div{      display:inline-block;      padding:5px;      margin:10px;      border:1px solid #ccc;      transition: 0s background-color;      transition-delay:1s;  }  div:hover{      background-color:red;  }
<div>delayed hover</div>

Demo of delay only on hover on:

div{      display:inline-block;      padding:5px;      margin:10px;      border:1px solid #ccc;      transition: 0s background-color;  }  div:hover{      background-color:red;          transition-delay:1s;  }
<div>delayed hover</div>

Vendor Specific Extentions for Transitions and W3C CSS3 transitions

like image 173
Gabriele Petrioli Avatar answered Oct 09 '22 21:10

Gabriele Petrioli