27

I've got a box that changes size when being hovered. However, I would like to delay the mouseout stage, so that the box keep the new size for a few seconds, before getting the old size back.

div {
    width: 70px;
    -webkit-transition: .5s all;    
}

div:hover {
    width:130px;
}

Is this possible to do WITHOUT Javascript and only CSS3? I only have to care about supporting webkit.

1
  • have you tried css3 animation property? i have tried some things with animation property, but i am not sure that is what you want. but if you want i can give you that. Commented Feb 22, 2012 at 11:01

2 Answers 2

50
div {
    width: 70px;
    -webkit-transition: .5s all;   
    -webkit-transition-delay: 5s; 
    -moz-transition: .5s all;   
    -moz-transition-delay: 5s; 
    -ms-transition: .5s all;   
    -ms-transition-delay: 5s; 
    -o-transition: .5s all;   
    -o-transition-delay: 5s; 
    transition: .5s all;   
    transition-delay: 5s; 
}

div:hover {
    width:130px;
    -webkit-transition-delay: 0s;
    -moz-transition-delay: 0s;
    -ms-transition-delay: 0s;
    -o-transition-delay: 0s;
    transition-delay: 0s;
}

This will trigger the mouseover state right away, but wait 5 sec till the mouseout is triggered.

Fiddle

Sign up to request clarification or add additional context in comments.

4 Comments

edited to add non webkit prefixes too - it's just good practice
on the "div" tag definition, isn't specifying "transition:" and "transition-delay" essentially a duplicate? The first value of the transition spec IS the delay value, no?
@Screenack No, the first value is the duration of the transition - how long it takes to complete once it gets going.
awesome use of transitions, patad.
9

transition can be declared as

transition: .5s all 5s

(shorthand, the first number is duration, the second number is delay) then you don't need the separate transition-delay

sorry, can't add as a comment as I don't have enough points

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.