I have a button with an animated hover effect where the background slides together and then when the mouse leaves it splits vertically and moves to the top/bottom. I cant figure out how to get it so that when the mouse leaves the background just reverses and the 2 halves go back to the sides instead of the top and bottom?
Here's the CSS that's driving it:
.bannerbuttonV1 {
--cblack: #282828; /* the color*/
--_p: 0%;
box-shadow: 0 0 0 .1em inset var(--cblack);
--_g: linear-gradient(var(--cblack) 0 0) no-repeat;
background:
var(--_g) calc(var(--_p,0%) - 100%) 0%,
var(--_g) calc(200% - var(--_p,0%)) 0%,
var(--_g) calc(var(--_p,0%) - 100%) 100%,
var(--_g) calc(200% - var(--_p,0%)) 100%;
background-size: 50.5% calc(var(--_p,0%)/2 + .5%);
outline-offset: .1em;
transition: background-size .4s, background-position 0s .4s, color .4s;
}
.bannerbuttonV1:hover {
--_p: 100%;
color:#fff;
transition: background-position .4s, background-size 0s;
}
<div class='bannerbuttonV1'>
shop now
</div>
Here's an example of it:
https://codepen.io/Mark-Edlington/pen/JjVWVWB
I found this code online and have adapted it a little, if anyone knows a better way to achieve this then I'm all ears. I'm sure I only need to use 2 background lines rather then 4 but it was setup initially so that the 4 quarters of the background moved away to the 4 corners.
Thanks
background.background-sizeto50%.transitionto contain onlybackground-position .4sandcolor .4s.transitionproperty from:hovered rule.Snippet: