Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css transition: choose different speed for hover out

Tags:

html

css

Is it possible to choose a different timing/speed for transition in css so when mouse hover over a div it expands with different speed than the speed it retracts back to its original width not hover state.

I have tried declaring different transition speeds in :hoer and normal state styling, however, only normal state style seems to apply.

http://jsfiddle.net/tpf8mv51/3/

Problems:

1st) it goes with same speed it expanded with.

2nd) zindex takes effect after animation is completed for reasons i don't gte.

3rd) other images get affected even though they shouldn't, by affected i mean they 99% of time disappear till animation is done.

* {
    margin: 0;
    padding: 0;
}
body {
    overflow: hidden;
}
.main {
    font-size: 0;
    height: 100%;
    width: 100%;
    display: none;
    z-index: -1;
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
}
.main img {
    -webkit-user-select: none;
    width: 25%;
    -webkit-transition: transform .5s;
    transform-origin: left;
    z-index: 0;
    vertical-align: top;
}
.main img:hover {
    transform: scale(1.3, 1);
    z-index: 1;
}
like image 839
Muhammad Umer Avatar asked Sep 21 '14 00:09

Muhammad Umer


People also ask

How do I change the hover speed in CSS?

To set the speed of the hover, use the transition-duration property. To set the hover, use the :hover selector.

How do you do a transition on hover?

CSS transitions allows you to change property values smoothly (from one value to another), over a given duration.

How do you do different hover effects in CSS?

The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.


1 Answers

Don't fret. try this (quick IN, slow OUT):

.main img {
  width: 25%;
  height: 100%;
  transition: width 2s ease;
}
.main img:hover {
  width: 50%;
  transition: width .5s ease;
}

Your Fiddle as I can see it only has one transition. If you're only changing the width, tell it to change the width, which has full browser support, rather than calling transform with all the attendant prefixes.

like image 174
AJFarkas Avatar answered Sep 30 '22 13:09

AJFarkas