Here is a crude example to help show what I would like: http://jsfiddle.net/GVaNv/
I was wondering if there is anyway to make the overlay transition
in from the left, but to then leave from the right side.
So, on hover, the overlay comes in as it is in the example, but instead of retreating back to the left, to transition
s to the right.
Is this possible? (doesn't necessarily need to use transition
, I'm open to any way to do it).
By specifying the transition on the element itself, you define the transition to occur in both directions. That is, when the styles are changed (e.g. on hover on), they properties will transition, and when the styles change back (e.g. on hover off) they will transition.
The transition property is a shorthand of four CSS properties, transition-property , transition-duration , transition-timing-function , transition-delay .
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.
That's the concept of multi-step animations in a nutshell: more than one change taking place in the animation from start to finish.
Here is a simple solution that does not require more HTML or JavaScript:
.box {
height: 100px;
width: 250px;
background: aqua;
position: relative;
overflow: hidden;
}
.overlay {
position: absolute;
background-color: rgba(0, 0, 0, 0.5);
width: 100%;
color: white;
padding: 10px;
left: -270px;
margin-left: 520px;
bottom: 0;
transition: left 300ms linear, margin-left 300ms ease-out;
}
.box:hover .overlay {
left: 0;
margin-left: 0;
transition: left 300ms ease-out;
}
<div class="box">
<div class="overlay">
Overlay
</div>
</div>
This leverages the margin for the animation. It works as follows:
left
is positioned to the left of the element).0
without an animation. This allows the left
animation to occur from the left side of the element.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With