Let's break down this query into two main components:
What causes the erratic behavior of hovering?
The issue, as highlighted by Palpatim, is that when the cursor hovers over the unfold-button
, it tends to abruptly move away. To rectify this, we need a stationary element that captures the hover action without displacing itself. One solution involves introducing a new div like so:
<div class="container">
<div class="unfold-button orange">
Hello World
</div>
</div>
Correspondingly, let's make alterations to the CSS selector accordingly:
.container:hover .unfold-button {
By implementing this in your HTML code, you should notice a stable hovering experience devoid of flakiness. However, although the glitchy movement has been addressed, the animation still fails to revert to its original position. This leads us to our next question:
Why doesn't the animation reverse itself?
Essentially, the absence of animation-fill-mode
does not imply automatic reversal once the animation ceases. It merely dictates how certain attributes are filled out pre and post-animation. Removing the line specifying animation-fill-mode
reveals that the sole distinction lies in reverting back after completion.
Furthermore, elements do not retain memory of previous animation
settings, resulting in an instantaneous shift to their latest designation once the attribute alters. Consequently, the abrupt transition from the hovered state back to the original configuration occurs due to the forgotten animation assignment.
To tackle this issue, especially with the simplistic nature of the unfold
animation, it's advisable to portray it as a transition instead:
.unfold-button {
/* ... */
border-style: none;
box-sizing: border-box;
transform-origin: 50% 100%;
-webkit-transform-origin: 50% 100%;
-webkit-transition: 0.5s;
transform: rotateX(0deg);
-webkit-transform: rotateX(0deg);
}
.container:hover .unfold-button {
-transform: rotateX(180deg);
-webkit-transform: rotateX(180deg);
}
Note the continuous presence of the transition
attribuomeanibutes during both the active and inactive states. Similar to animation
, its portrayal that dictates any outcome hinges on its immediate inclusion.
In conclusion...
If the presented HTML and CSS codes align with what is being referred to here, everything should function harmoniously.
For further insights on reversing CSS animations upon hover-out, refer to:
How can CSS Animation reverse upon hover-out?