How can I create a smooth animation with CSS3 that transitions back smoothly when the element is no longer being hovered over, instead of just snapping back abruptly?

http://jsfiddle.net/nicktheandroid/vX7CV/10/

This is a straightforward example, however for my specific requirements, I need to utilize animation instead of transition.

During hovering over the element, the animation smoothly transforms the element; but when moving away from it, it abruptly reverts back to its original state without any smooth transition.

Is there a method to make it smoothly animate back to its original settings rather than snapping back as it currently does?

I must use animation for the hover event, but I am open to using transition when hovering off the element if it can achieve the desired effect. However, I have not been able to make this work so far.

Answer №1

After thorough testing, I can confirm that your version works smoothly on Google Chrome and Firefox as well.

Here is the updated code:

HTML:

<ul>
    </li>test</li>
</ul>

CSS:

ul {
    background-color:black;
    color:white;
    width: 100px;
    height:100px;
}
@-moz-keyframes flow-down {   
    0% {
      padding-bottom: 0%;
    }
    100% {
      padding-bottom: 30%;
    }
}
@-webkit-keyframes flow-down {   
    0% {
      padding-bottom: 0%;
    }
    100% {
      padding-bottom: 30%;
    }
}
ul:hover {
    -moz-animation-name: flow-down;
    -moz-animation-duration: 0.5s;
    -moz-animation-timing-function: ease-in-out;
    -moz-animation-fill-mode:forwards;
    -webkit-animation-name: flow-down;
    -webkit-animation-duration: 0.5s;
    -webkit-animation-timing-function: ease-in-out;
    -webkit-animation-fill-mode:forwards;
}

View the JSFiddle version for reference:

http://jsfiddle.net/NQ5xk/1/

I hope this information proves useful to you.

Best regards

Answer №2

If you modify the 'position' or 'z-index' attributes in Firefox while an animation is running, the animation will not be able to continue smoothly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for effectively utilizing the :valid pseudo-class in Material-UI components to dynamically alter the border styling

Currently, I am attempting to adjust the border color of Mui TextFields using createTheme from Mui v5 when the input is valid. The border itself is defined within the ::before and ::after pseudoclasses. For the TextFields, I am utilizing variant="stan ...

Eliminating the default inline style automatically

My goal is to hide a table row until a radio button is clicked. I attempted using display:none;, but it did not work. Upon inspecting the code in my developer tools, I noticed that the specific table row has a style attribute style="display: table-row; whi ...

Laravel - Automatically assign a class to a nav-link when its generated URL corresponds to the current route

I'm currently working with Bootstrap 4 and I am attempting to dynamically add the class active to my nav-item elements when their href attribute matches the current URL. In my HTML code, I have implemented a simple URL generator as follows: <ul c ...

Set a CSS rule to style every other row in a table, starting from the second row and resetting after

Is there a way to refresh the even and odd count in CSS whenever a specific row is shown? Here's an example setup: header header header even even even odd odd odd Subhead Subhead Subhead even even even How can I ensu ...

How to insert an image into a div element in HTML5

I have a basic div element shown below: <div class="avatar"> <img src="http://quickshare.my3gb.com/download/testpic.jpg" /> </div> (The original image size is 216 * 216 pixels) and the CSS I am using is as follows: .avatar { float: r ...

What techniques does Google use to craft mobile-friendly fixed backgrounds and parallax content within iframes?

Currently, I am working on a test that involves utilizing an intersectionobserver in conjunction with iframe postMessage to adjust the background image in a translate3d manner within the iframe. However, this method is causing significant jitter and potent ...

How can I implement a daily-updating timestamp on a website using bootstrap and javascript, particularly for review and blog posts?

I am looking to add a timer and date stamp feature to my website built with Bootstrap, using JavaScript or any other necessary tools. Typically, on platforms like Google or in blog posts, there is a small text under the user's photo and name indicatin ...

Difficulties arise when dealing with card elements and scrolling on a

Currently working on an ecommerce simulation project for a course, I successfully implemented a featured section with cards. However, when it comes to scrolling, I am facing an issue where the cards overlap with my sticky navbar as I scroll down. If anyo ...

Create a custom CSS style to replace the default jQuery hide() function

HTML <div class="adm-input" <?php if(!empty($admin_fee) || $admin_fee != "") echo "style='display:block'"; ?> id="fees-input"> <label>Admission Fees(<i class="fa fa-inr"></i>)</label> <div class="in ...

Fresh sheet with a view through the window

I need to print a table and two popup windows when an action is triggered, but I am facing issues with the page-break in CSS. None of the solutions I have attempted so far seem to work. Currently, the two pop-up windows overlap with the table data, and I w ...

JavaScript CompleteLink message

Hey there, I've come across a JavaScript code for a countdown timer but need some assistance with it. The issue I'm facing is that within the code, there's a line that displays a message to the user when the timer reaches zero. I want to kn ...

The application of border-radius to a solitary side border forms a unique "crescent moon" shape rather than a traditional semi-circle

Is there a way to transform this shape into a regular semicircle, avoiding the appearance of a moon, and change the image into a circle rather than an ellipsis? http://jsfiddle.net/226tq1rb/1/ .image{ width:20%; border-radius:500%; border-rig ...

Achieve consistent card body heights in Bootstrap 4 with the card group feature

I am working towards achieving a specific layout using Bootstrap 4's card-group feature, as shown in the image below: The goal is to have everything at the same height within each card (including card-header, card-title, and small subtext if present) ...

persistent image in HTML affecting the layout of the header

I have been struggling with positioning a sticky image above my navigation bar. Here is the code for the sticky image: img.sticky { position: -webkit-sticky; position: sticky; top: 0; width: 200px; z-index: 1000; } <div> <a href=" ...

What is the best way to add borders to my website design?

As someone brand new to the world of HTML and CSS, please be patient with me as I learn the ropes. :) Currently, I am in the process of building my own website to gain experience in web development. From the beginning, I envisioned a centered, light grey ...

Press anywhere outside the container to conceal it along with the button

Utilizing an Angular directive to hide div elements when the user interacts outside of them has been effective. However, there is a specific issue that arises when clicking outside of a div on a button that toggles the visibility of the div. The 'ang ...

Employing jQuery to implement a hover animation on IE9, it functions properly when hovering over but exhibits strange behavior upon exiting

My website features a quote box positioned to the right of the browser. When hovered over, it reveals a list of available dates. I initially tried using CSS transitions which worked on all browsers except for IE - no surprise there. So, I turned to jQuery ...

Replacing a predefined label in Volusion (for language translations)

I am currently working on a project using the Volusion platform, which unfortunately does not provide full interface editing capabilities. As a result, I am attempting to edit certain hardcoded labels in the HTML to display them in Spanish. After trying v ...

Visual element and form entry

I have a follow-up question regarding the same topic. How can I edit it to move up in the list or does that happen automatically? Now, onto the main question - I have an image and an input box both contained within a span, and I want to display them next ...

What causes certain div content to be absent from ZoneTemplate within an ASP.NET web part?

Check out this snippet of code: <asp:WebPartZone ID="Zone1" runat="server" Width="100%" PartChromeType="None" Padding="0" PartStyle-CssClass="NoPadding" PartStyle-BackColor="Transparent" BackColor="Transparent" PartChromeStyle-BackColor ...