Is there a way to use CSS animation and transform to create a flip effect on two different divs, flipping them up and then back down with pauses and looping in between?

I have a query about CSS animation and transform. I am looking to create a flipping effect on two divs - one flips up from the bottom, then back down, followed by the second div flipping up and back down. I want this sequence to repeat indefinitely with pauses in between so they don't flip simultaneously.

NOTE: I've attempted using animation-delay and various CSS animation tricks such as defining keyframes at different percentages, but I haven't been able to achieve the desired effect.

Edit: Here is a JSFiddle link demonstrating the issue I'm facing: https://jsfiddle.net/9qx0Lnj6/1/

Quick Update: Here's a GIF illustrating what I'm trying to accomplish visually:

<div class="container">
  <div class="icon-wrap">
    <div class="icon-one icon">
        One
    </div>
    <div class="icon-two icon">
        Two
    </div>
  </div>
</div>

`.container {
      position: relative;
      .icon-wrap {
        position: relative;
        width: 50px;
        height: 50px;
        overflow:hidden;
        perspective:1000px;
        .icon {
          position:absolute;
          width:50px;
          height:50px;
        }
        .icon-one {
          background:red;
          transform-origin: bottom;
          transform-style: preserve-3d;
          animation: 3s flip 2s infinite linear;
        }
        .icon-two {
          background:blue;
          transform-origin: bottom;
          transform-style: preserve-3d;
          animation: 3s flip infinite linear;
        }
      }
    }`

@keyframes flip{
                0% {
                transform: rotateX(180deg)
              }
              14% {
                transform: rotateX(0deg);
              }
              100% {
                transform: rotateX(0deg);
              }
    }

Answer №1

Check out this cool animation:

var a = document.querySelectorAll('div');
a = Array.prototype.slice.call(a);

var timings = {
  easing: 'ease-in-out',
  iterations: Infinity,
  direction: 'alternate',
  fill: 'both'
}

a.forEach(function(el, i, ra) {
  timings.delay = i  * 2400;
  
  timings.duration = 5000;
  el.animate([
    {transform: 'rotateX(180deg)'},
    {transform:'rotateX(-180deg)'}
  ], timings);
  
  timings.duration = 7500;
  el.animate([
    {opacity: 1},
    {opacity: 0}
  ], timings);
  
  timings.duration = 10000;
 
});
$background: #e45349;
$light: #efefff;

body {
  background: $background;
  display: flex;
  justify-content: center;
}

div {
    display:     inline-block;
  
   position:   absolute;
  height:     inherit;
   text-align: center;
  width:      inherit;
  
  transform-style:     preserve-3d;
  backface-visibility: hidden;
   width:70px;
      height:50px;

      -moz-border-radius: 10px;
      -webkit-border-radius: 10px;
      border-radius: 10px;
}



 
    

    .icon-one:before,
   .icon-one:after {
      content: '';
      position: absolute;
      border-bottom: 30px solid red;
      border-left: 10px solid transparent;
      border-right: 10px solid transparent;
      top: 30px;
      left: 20px;
      transform: rotate(-140deg);
    }
    
    .icon-four:before,
   .icon-four:after {
      content: '';
      position: absolute;
      border-bottom: 30px solid yellow;
      border-left: 10px solid transparent;
      border-right: 10px solid transparent;
      top: 30px;
      left: 20px;
      transform: rotate(-140deg);
    }
    
    
    
     
    .icon-three:before,
   .icon-three:after {
      content: '';
      position: absolute;
      border-bottom: 30px solid blue;
      border-left: 10px solid transparent;
      border-right: 10px solid transparent;
      top: 30px;
      left: 20px;
      transform: rotate(-140deg);
    }
    
    .icon-two:before,
   .icon-two:after {
      content: '';
      position: absolute;
      border-bottom: 30px solid green;
      border-left: 10px solid transparent;
      border-right: 10px solid transparent;
      top: 30px;
      left: 20px;
      transform: rotate(-140deg);
    }
.icon-one{background: red;}
.icon-two{background:  green;}
.icon-three{background: blue;}
.icon-four{background:  yellow;}
<div  class="icon-one"><br>One</div>
<div class="icon-two"><br>Two</div>
<div  class="icon-three"><br>Three</div>
<div  class="icon-four"><br>Four</div>

Here's another fun animation:

.container {
  display:     inline-block;
  width:       64px;
  height:      64px;
  perspective: 700px;
}
.icon, .icon-one, .icon-two{
  position:   absolute;
  height:     inherit;
  width:      inherit;
  transition: all .5s;
  transform-style:     preserve-3d;
  backface-visibility: hidden;
   width:50px;
      height:50px;

}

/* ::: FACES */
.icon-one{background: red;}
.icon-two{background:  green;}

/* ::: SETUP FACES */
}
.icon-wrap .icon-one{transform: rotateX(180deg);}
.icon-wrap .icon-two{transform: rotateX(-180deg);}

/* ::: HOVER EFFECTS (Remove Automated for this to work) */

.icon-wrap:hover .icon{ transform: rotateX(180deg); }

/* ::: AUTOMATED EFFECTS */

.icon-wrap .icon{
  animation: icon-wrap 5s 1s infinite alternate ease-in-out;
  -webkit-animation: icon-wrap 5s 1s infinite alternate ease-in-out;
}



@keyframes icon-wrap {
  0% { transform: rotateX(0deg); }
  100% { transform: rotateX(180deg); }
}
@-webkit-keyframes icon-wrap {
  0% { transform: rotateX(0deg); }
  100% { transform: rotateX(180deg); }
}
<div class="container icon-wrap">
  <div class="icon">
    <div class="icon-one"> One</div>
    <div class="icon-two"> Two</div>
  </div>
</div>

For more details, visit this link

Also, check out this helpful resource

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

Input field in a tableview

I have a ListView that features a dropdown, 4 textboxes and buttons. My goal is to only show the fourth textbox (enclosed in a span) when the dropdown value in each row of the ListView is set to 2. For instance, if there are 5 records being displayed in t ...

Mysterious Chrome glitch causes SVG element to shift down by 2 pixels

I am currently facing an issue with creating image links from an SVG spritesheet that is causing cross-browser problems between Chrome, Safari, and Firefox. Here are some of the anchor tags I am using: <a href="#" id="twitter-logo" class="socialIcon"&g ...

Ensuring Unique CSS for Diverse Devices: A User-Agent Driven Approach

I am facing multiple challenges and working towards finding solutions. I have developed a webpage and now I want to redirect the link to the CSS file based on the user agent. `<script type="text/css" src="style.css"> </script>` However, inst ...

Uncheck the box for disabling the bottom row of HTML tables

I need help with disabling a check box under certain conditions. Specifically, I want to disable the check box if there is only one row in the table or if it's the last row, but for some reason it's not working as expected. Here is the HTML: &l ...

What could be causing my navigation bar to malfunction?

Being fairly new to HTML and CSS, I have been struggling with my nav bar. Despite multiple attempts to fix it, the dropdown items do not appear when hovered over. Changing display: none; to display:block; only results in the items dropping down to the next ...

experiencing a problem with the scrollTo() function

I am encountering difficulty in finding the correct X and Y coordinate values to move an image using mouse scroll within a div. I have included my sample code below. I have successfully managed to scroll the image without using a div. Can anyone assist m ...

What could be the reason for the absence of this Javascript function in my attribute?

I have been working on an app using electron, and I have a function that successfully adds tabs to the app. The issue arises when I try to add tabs via JavaScript with the onclick attribute - they show up as expected but do not execute the code to hide and ...

Display the actual runtime hyperlink while utilizing the asp tag helper

Whenever I use asp-tag helpers to create a hyperlink, the result is displayed like this: <a asp-page="/demo">Demo</a> The actual html output looks like this: <a href="/test/Demo">Demo</a> However, instead of displaying "Demo" to ...

Having trouble with tabs in jQuery?

I'm having trouble setting up tabs in a reservation form with 3 tabs that include text boxes for user input. I can't seem to get it working properly and I'm not sure where I've gone wrong. Could it be due to the placement of the content ...

Having Trouble Aligning Contents in a Row Horizontally using Bootstrap 5

My Images are refusing to align in a horizontal row no matter what I try. Output: https://i.sstatic.net/echGV.png .img-size-square { width: 100%; height: auto; max-width: 400px !important; max-height: 400px !important; } .container-f ...

jQuery's ajax function fails to detect a 401 error

Having trouble with exception handling on the client side? Everything was going smoothly until I introduced HTTP401. Take a look at my base controller that overrides OnException: protected override void OnException(ExceptionContext filterContext) { va ...

Having trouble replacing scss variables in react-h5-audio-player

I recently integrated react-h5-audio-player into my project and followed the instructions on the README page to customize the styles by updating the SCSS variables that control the colors. However, it appears that my custom styles are not being applied. An ...

What are the steps to employ a query string to display a specific image?

If I understand correctly, I can utilize a query string and parse it to display certain information. How would I apply that concept to load a specific image? https://codepen.io/anon/pen/qYXexG <div id="gallery"> <div id="panel"> <img ...

Position Bootstrap buttons to the right side

I am looking to reposition the buttons in the header, shifting them from the default right side to the left side. Specifically, I want to move Abcd to the right side and have A1, A2, A3, A4, and A5 displayed on the left side. Here is my current code: < ...

Can you explain the purpose of the role attribute in XHTML? How is it commonly utilized?

After reviewing W3C's information about the role attribute, I am still unclear about its purpose. Is the role attribute meant to simply clarify the code, or do some browsers or spiders interpret it in a specific way? Could the role attribute serve as ...

Is there a way to rewrite HTML by substituting the parent tag with a different tag than the children's tag?

Upon retrieving HTML content from an API, I am faced with the task of processing it. Here is a snippet of the data: [ { id: 1, content: '{html...}' }, { id: 2, content: '{html...}' } ] A ...

Issues with Converting JSON to HTML Table using JavaScript

Issues with Converting JSON to HTML Table Using JavaScript I've been trying to create a function that will display the contents of a JSON file in an HTML table. However, I keep getting an undefined error. Despite being able to see the data displayed ...

Discover the position of a dynamically added element

Is there a way to identify the specific dynamically added checkbox that was clicked, whether by index or name? I came across a similar question with a solution in this JSFiddle: JSFiddle Instead of just displaying "clicked", I would like it to show someth ...

Prevent Cross-Site Scripting attacks in Laravel by sanitizing user input, even when allowing HTML tags

What measures can be taken to protect against XSS attacks when a user is allowed to use HTML tags, such as in a textarea element? Avoiding the stripping or escaping of all tags complicates the situation and rules out the option of using {{ }}. It's a ...

What are the best practices for maximizing the efficiency of bootstrap-sass?

Currently, I am exploring npm modules and came across bootstrap-sass. After downloading the modules, I was seeking a solution to compile scss into the static folder of my application, as well as the js bootstrap files. However, after checking the npmjs do ...