Rotating and moving two boxes using CSS3 transformations

I have two boxes, each measuring 200px by 200px, that I would like to animate using CSS animations. The first box (upper box) should rotate from rotateX(0deg) to rotateX(90deg) with a transform-origin of center top. The second box should follow the bottom line of the first box, so it should be animated from translateZ(0px) translateY(0px) to translateZ(200px) translateY(-200px). This alignment is essential only at the start and end of the animation. You can see an example of this animation here.

In the example, I have used only -webkit- and -moz- prefixes.

You can view the JSFiddle here

HTML

<div class="box box-1"></div>
<div class="box box-2"></div>

CSS

body{
    padding: 200px 0 0 0;
    margin: 0;
    background-color: orange;
    -webkit-transform-style: preserve-3d;
    -webkit-perspective: 1000px;

    -moz-transform-style: preserve-3d;
    -moz-perspective: 1000px;
}
.box{
    height: 200px;
    width: 200px;
    margin: 0 auto;
    -webkit-transform-origin: center top;

    -moz-transform-origin: center top;
    opacity: 0.7;
}
.box-1{
    background-color: blue;
    -webkit-animation-duration: 3s;
    -webkit-animation-name: boxOne;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-direction: alternate;

    -moz-animation-duration: 3s;
    -moz-animation-name: boxOne;
    -moz-animation-iteration-count: infinite;
    -moz-animation-direction: alternate;
}
.box-2{
    background-color: purple;
    -webkit-animation-duration: 3s;
    -webkit-animation-name: boxTwo;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-direction: alternate;

    -webkit-animation-duration: 3s;
    -webkit-animation-name: boxTwo;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-direction: alternate;
}





@-webkit-keyframes boxOne{
  from {
    -webkit-transform: rotateX(0deg);
  }

  to {
    -webkit-transform: rotateX(90deg);
  }
}


@-webkit-keyframes boxTwo{
  from {
    -webkit-transform: translateZ(0px) translateY(0px);
  }

  to {
    -webkit-transform: translateZ(200px) translateY(-200px);
  }
}



@-moz-keyframes boxOne{
  from {
    -moz-transform: rotateX(0deg);
  }

  to {
    -moz-transform: rotateX(90deg);
  }
}


@-moz-keyframes boxTwo{
  from {
    -moz-transform: translateZ(0px) translateY(0px);
  }

  to {
    -moz-transform: translateZ(200px) translateY(-200px);
  }
}

Answer №1

The animation you're working on seems quite intricate. Have you considered exploring various easing methods for the translation process? If you simplify the issue to a 2D plane, you'll notice that the top element's height increases, but the growth rate accelerates over time. By incorporating easing into the animation of the second element, you can replicate this gradual increase over time. Check out the following resources for some assistance: The easeInCirc option is likely the best fit for your needs.

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

Enhance CSS delivery for the items listed below

Reduce the delay caused by rendering JavaScript and CSS above-the-fold. There are 16 CSS resources currently blocking the rendering of your page. This delay could be affecting the loading time of your content. To improve this issue, consider deferring or ...

The `required` attribute is ineffective when used with the `<form>` element

My required attribute isn't enforcing mandatory field completion before form submission. HTML Code: <!-- Modal Content --> <form class="modal-content2"> <div class="container3"> < ...

Display XML information when a row in the table is selected

I am working with an XML data sheet and utilizing ajax to extract information from it in order to generate specific tabs and construct a table of data. However, I am encountering a challenge when attempting to display details in adjacent divs once a row of ...

Looking to execute a PHP script upon form submission

I have a form that I need to submit in order for a PHP script to run using AJAX. <form method="post" action="index.php" id="entryform" name="entryform"> <input type="submit" name="submit" value="Submit" onclick="JavaScript:xmlhttpPost('/web/ ...

Issue with changing the height of a textarea in a mobile browser when it is

I'm currently facing an issue specific to mobile devices that I have also encountered on Google Chrome (even when using the developer tools in mobile view). The problem is quite straightforward. There is a simple form on the website, consisting of a ...

Avoid Scroll Below Stuck Navigation

I've been searching for a solution to my issue for some time now, and while I've come across many articles discussing similar problems, none of them seem to address my specific problem. In my React app, I have a mobile version where users can ta ...

The bootstrap navigation bar appears in a vertical orientation rather than the expected horizontal

My page is displaying the navbar vertically instead of horizontally. <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1,shrink-to ...

Adjust the appearance of a div according to the input value

When a user inputs the correct value (a number) into an input of type "number," I want a button to appear. I attempted var check=document.getElementById("buttonID").value == "1" followed by an if statement, but it seems I made a mistake somewhere. Here&ap ...

View a pink map on Openlayers 2 using an iPhone

I am currently working on a project where I am trying to track my location using my smartphone and display it on a map. To achieve this, I am utilizing openlayers 2. However, I am encountering an issue. When I implement the code below in a Chrome Browser ...

Maintain the fixed position of the Google Map <div> while allowing background <div>s to scroll

I'm having trouble keeping a Google Map div fixed on the screen while allowing my background, consisting of multiple scrolling divs with content inside, to scroll as normal. My attempt to wrap the map div in another fixed div resulted in the map disa ...

Should the username be specified but the password left blank, then an error message will be shown

<div class="form"> <h1>Sign In</h1> <form action="" method="post" name="login"> <input type="text" name="username" placeholder="Enter username" required /> <input type="password" name="password" placeholder="Enter password" ...

The art of placing images using CSS

I'm having trouble aligning the images into two rows of three, with the news section on the right side below the navigation bar. I've tried different methods but can't seem to get it right. Both the image and link should be clickable, but I& ...

The issue of footer overlapping the login form is observed on iOS devices while using Safari and Chrome

Unique ImageI am currently working on an Angular 8 project with Angular Material. I have successfully designed a fully functional login page. However, I am encountering a problem specifically on iOS devices such as iPhones and iPads, whether it is Safari o ...

Achieving perfect alignment of an image within a Twitter Bootstrap cell when the height of the cell is uncertain

I have a bootstrap grid and I am attempting to center an image (200x100 as shown in the provided example) within a cell. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!DOCTYPE html> <html& ...

How to style HTML li elements to wrap like sentences within a paragraph

I am looking to format text list elements in a way that they wrap like sentences within a paragraph. Here is the accompanying HTML & CSS code snippet that demonstrates how li element behaves when it exceeds the width of the ul container. ul { ...

The table's width exceeds the appropriate size

Take a look at the code snippet below <%-- Document : index Created on : Feb 7, 2014, 1:03:15 PM --%> <%@page import="java.util.Map"%> <%@page import="java.util.Iterator"%> <%@page import="analyzer.DataHolder"%> <%@p ...

React Intersection Observer not functioning properly

Hey there! I'm trying to create an animation where the title slides down and the left element slides to the right when scrolling, using the intersection observer. Everything seems to be fine in my code, but for some reason it's not working. Any t ...

Using the jQuery/JavaScript operator is similar to the SQL LIKE query with the wildcard %

Is there a way to search for a specific part of my input using JavaScript/jQuery? I've tried two different methods, but neither yielded any results. <script type="text/javascript> $("#button").click(function () { $("#DivToToggle").toggle(); ...

How can I turn off Angular Grid's virtualization feature, where Angular generates div elements for the grid based on height and width positions?

Currently, I am working with an Angular grid (ag-grid) that dynamically creates div elements in the DOM to display data as the user scrolls or views different sections. As part of my testing process using Selenium WebDriver, I need to retrieve this data fr ...

Integrating md-chips md-separator-keys with md-autocomplete: A step-by-step guide

My experience with using md-chips and md-autocomplete reveals an issue: when I incorporate md-separator-keys, it functions as expected. However, upon adding md-autocomplete, the md-separator-keys functionality ceases to work. This is how my code is struct ...