Creating Animated Rotation Resets Using CSS Keyframes

My latest creation involves an animated display of leaves "waving" gracefully. These leaves come with a default rotate value from tailwind:

@keyframes growSize {
  0% {
    transform: rotate(0deg);
    max-height: 0;
  }
  25% {
    max-height: 9999px;
  }
  50% {
    transform: rotate(5deg);
  }
  75% {
    transform: rotate(-5deg);
  }
  100% {
    transform: none;
  }
}

.leaf-animation {
  animation-name: growSize;
  animation-delay: 2.5s;
  animation-duration: 2s;
  animation-timing-function: ease-in-out;
  animation-fill-mode: both;
}
<script src="https://cdn.tailwindcss.com/3.3.3"></script>

<div class="relative z-0 ml-32 mt-16 w-max">
  <img class="rounded-l-md rounded-r-3xl" src="https://placehold.co/308x392" width="308" height="392" />
  <svg viewBox="0 0 87 97" class="leaf-animation absolute -z-10 -rotate-45 w-20 -top-14 -left-14"><use href="#leaf" /></svg>
  <svg viewBox="0 0 87 97" class="leaf-animation absolute -z-10 -rotate-45 -scale-x-100 w-40 bottom-4 -left-32"><use href="#leaf" /></svg>
  <svg viewBox="0 0 87 97" class="leaf-animation absolute -z-10 rotate-45 w-36 bottom-32 -right-24"><use href="#leaf" /></svg>
</div>

<svg class="w-0 h-0" viewBox="0 0 87 97" fill="none" xmlns="http://www.w3.org/2000/svg" id="leaf">
  <path d="M85.2 47C85.2 47 82.7 51.6 80.6 52.4C78.6 53.2 57.7 62.4 54.3 61.9C51 61.3 57.7 56.2 75.5 48.7C93.3 41.3 75.5 20.6 75.5 20.6L75.2 21.5C72.9 29.4 67.6 36.1 60.3 39.8C57.4 41.3 54.7 43.6 52.2 43C44.2 40.9 84.7 21.8 64.6 14.1C44.5 6.4 39.3 0.4 39.3 0.4C35.2 7.2 18.6 11.2 18.6 18.7C18.7 26.2 31.5 31.4 28.1 34.2C24.8 37.1 14.7 22.1 14.7 22.1C7.20003 28.6 6.70003 33.5 6.70003 33.5C10.1 47.9 31.2 57 21.7 56.2C7....

        

I want the waving animation to be synchronized with their original rotation and then revert back to the initial rotation afterwards

Answer №1

The Tailwind utility classes associated with rotate-* implement the rotation effect using the CSS variable --tw-rotate. To create a dynamic rotation effect, this same variable can be utilized within the @keyframes rule by incorporating the calc() function to adjust the rotation relative to its initial value:

@keyframes growSize {
  0% {
    transform: rotate(var(--tw-rotate, 0deg));
    max-height: 0;
  }
  25% {
    max-height: 9999px;
  }
  50% {
    transform: rotate(calc(var(--tw-rotate, 0deg) + 5deg));
  }
  75% {
    transform: rotate(calc(var(--tw-rotate, 0deg) - 5deg));
  }
  100% {
    transform: rotate(var(--tw-rotate, 0deg));
  }
}

.leaf-animation {
  animation-name: growSize;
  animation-delay: 2.5s;
  animation-duration: 2s;
  animation-timing-function: ease-in-out;
  animation-fill-mode: both;
}
<script src="https://cdn.tailwindcss.com/3.3.3"></script>

<div class="relative z-0 ml-32 mt-16 w-max">
  <img class="rounded-l-md rounded-r-3xl" src="https://placehold.co/308x392" width="308" height="392" />
  <svg viewBox="0 0 87 97" class="leaf-animation absolute -z-10 -rotate-45 w-20 -top-14 -left-14"><use href="#leaf" /></svg>
  <svg viewBox="0 0 87 97" class="leaf-animation absolute -z-10 -rotate-45 -scale-x-100 w-40 bottom-4 -left-32"><use href="#leaf" /></svg>
  <svg viewBox="0 0 87 97" class="leaf-animation absolute -z-10 rotate-45 w-36 bottom-32 -right-24"><use href="#leaf" /></svg>
</div>

<svg class="w-0 h-0" viewBox="0 0 87 97" fill="none" xmlns="http://www.w3.org/2000/svg" id="leaf">
  <path d="M85.2 47C85.2 47 82.7 51.6 80.6 52.4C78.6 53.2 57.7 62.4 54.3 61.9C51 61.3 57.7 56.2 75.5 48.7C93.3 41.3 75.5 20.6 75.5 20.6L75.2 21.5C72.9 29.4 67.6 36.1 60.3 39.8C57.4 41.3 54.7 43.6 52.2 43C44.2 40.9 84.7 21.8 64.6 14.1C44.5 6.4 ...
...
... 65.7 46.4C65.3 46.7 65 47 64.6 47.3C63.9 47.8 63.3 48.4 62.5 48.9C62 49.3 61.4 49.7 60.8 50.2C60.3 50.6 59.7 51 59.2 51.4C58.2 52.1 57 52.9 55.8 53.7C54.6 54.4 53.5 55.1 52.4 55.8C52 56 51.6 56.2 51.3 56.4C50.6 56.8 49.8 57.3 49.1 57.6C48.8 57.8 48.4 57.9 48.1 58.1C47.4 58.4 ...

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

:nth-child along with endless scrolling

In the development of a website, I encountered a situation where there is a grid of items with rows that float properly thanks to a specific CSS code: .collection .grid-item:nth-child(3n+1){ clear: left; } This code ensures that the first item in ea ...

Hover effect on two divs changing states

I was so close to solving this issue, but I'm stuck on the final part. Here's the code snippet I've been working on: /* valuecanvas */ #wrappercs { margin-top: 3px; width: auto; height: auto; display: block; float: right; bac ...

The vertical tab is not appearing correctly within the modal across various browsers

While attempting to showcase a vertical tab inside a Bootstrap 4 Modal, I've encountered an issue where the same modal appears differently in Google Chrome versus Firefox browsers. Here is the code I am utilizing: <!-- Latest compiled and minif ...

Shifting the MUI DataGrid Pagination table to the left with CustomPagination: A step-by-step guide

Hey everyone, I am currently diving into the MUI data grid to gain a better understanding. In order to meet my design requirements for a table view, I have incorporated the DataGrid component from MUI. For pagination, I am utilizing their custom implementa ...

Navigating the art of employing different fonts for a website

I am looking to incorporate the trainway font into my website, but I'm concerned that the user may not have it installed on their device. Is there a way to showcase text in a specific font without requiring the user to download and install it? Thank ...

Float: right; is causing distortion to the appearance of Div elements

I would like to style this image and text so that they float to the right with some spacing around them. However, when using float: right;, they end up extending beyond the default resolution excessively. #pageMain { margin: 100px; } #aboutGame { f ...

CSS Animation: a single transform property, excluding the other

Currently facing a challenge. I am manipulating an element by dragging it across the screen. When changing directions (left or right), I tilt the element in the direction it is moving, creating a gravity-like effect. To achieve smooth tilting, I have adde ...

Illuminate the expanded dropdown menu in a Bootstrap 5 navbar

Bootstrap 5 navbar allows for the creation of dropdown menus. Is there a way to highlight the current menu item when a dropdown is opened, similar to how it's done in Windows desktop applications? This feature is not provided by Bootstrap 5: https:/ ...

Control the line height in DataTables

Is there a way to adjust the line height for a tr using either DataTables settings or CSS? I've attempted different methods, but nothing seems to change the line-height. https://i.sstatic.net/GwFaD.png Table CSS ...

The (.svg) image does not cover the full width of the page

After creating an SVG image, I encountered a problem when trying to display it on a webpage. Even with the width value set to 100%, the image did not stretch all the way to the edges of the page, leaving small gaps at the edges. I attempted to switch the ...

Tips for ensuring child li pushes parent li down in mobile navigation

Hello there, I'm having trouble with mobile navigation. I have a main navigation menu with some hidden subnavigation items. When I click on a parent item, it opens the corresponding subnav, but it covers up all other parent items that come after it. ...

The conversion of HTML CSS list bullets to images is not functioning properly

Is there a way to change the bullet point of an li list to an image background? I have tried implementing it, but the image does not appear. Strangely, other images set as li backgrounds are also not showing up. My HTML code is validated by W3Validator, so ...

Class Background Imagery

Currently leveraging Wpbakery for my website design. Seeking to apply the FadeInUp animation solely to the background image rather than the entire row. Any suggestions on accomplishing this? Is there a method to assign a class solely to the background i ...

Preserve the original position of the inner <div> when animating the container <div> using JQuery

I am currently working on a small website and encountering some challenges with jQuery animation. My issue involves placing a single character text inside a circle and wanting it to grow when the user hovers over it, while keeping the inner text in its ori ...

Guide to setting up collapsible sections within a parent collapsible

I came across this animated collapsible code that I'm using: https://www.w3schools.com/howto/howto_js_collapsible.asp Here is the HTML: <button type="button" class="collapsible">Open Collapsible</button> <div class="content"> &l ...

Do the values returned by window.screen.width and height represent CSS pixels or physical screen pixels?

After exploring the API named screen and visiting this documentation link, my initial anticipation was that I would receive information regarding actual screen size pixels. https://developer.mozilla.org/en-US/docs/Web/API/Screen/width https://i.sstatic.n ...

Creating Image Overlays with Hover Effects using CSS and PHP Conditions

Looking for some assistance with a Minecraft server listing page I am working on for a client. I have never done this before and have encountered a roadblock. Take a look at this image (apologies for using Paint, I was in a hurry!) The goal is to have the ...

How to Turn Off Hover Effect in Essential Grid for Mobile Devices

My website, tyloz.com, features four panels on the homepage that act as landing pages. These panels have a hover effect that also works on mobile devices. However, I am looking to disable the hover and double tap functionality specifically on phones. Is th ...

Having difficulty developing a website layout design

Struggling to create a web layout using only HTML and CSS. Seeking assistance with the following code: * { margin: 0; padding: 0; box-sizing: border-box; } section { min-height: 100vh; width: 100%; display: flex; justify-content: center; ...

Automatically adjust the height of a React Native view

I am working on a component that consists of three views - one at the top, another in the middle with a specific height, and the last one at the bottom. I want the top and bottom views to adjust their heights accordingly. Although this may seem straightfor ...