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

ng-click-outside event triggers when clicking outside, including within child elements

I am looking to trigger a specific action when I click outside of the container. To achieve this, I have utilized the ng-click-outside directive which works well in most cases. However, there is one scenario where an issue arises. Inside the container, the ...

The color of the top bar remains unchanged when hovered over

I am struggling to design my personal website, and I can't seem to get the top bar to change color on hover. If you believe you have a solution, please provide your answer. index.html appears to be functioning properly, but perhaps additional adjustm ...

Firefox Cookie Expiry Date Automatically Set to One Week in Default Settings

I recently encountered an issue while trying to create a cookie that would persist for a year. Interestingly, the code I used worked perfectly on Chrome, as I could verify by checking the "Storage" in the dev tools. However, when I tried the same code on F ...

What is the syntax for using escape characters in Vue?

Looking to create a website similar to CodePen? I have developed a library of assets including buttons, cards, and effects, all built using vue.js. Each asset includes HTML, CSS, and sometimes JS code. In my vanilla JS version, I formatted the code using e ...

Struggling to retrieve a JSON object from an Express and Node application, only receiving an empty result

Can anyone assist me? I'm having trouble with the res.json() function in my code. It seems to work after the first request, but not after the second. Right now, my application is quite simple - it scrapes user data from social media platforms like Twi ...

Fluidity of Containers on Mobile Devices

I currently have a list structured like this: https://i.sstatic.net/ei4Xt.png In order to display more details about each list item, I've added a hidden div that can be toggled open like so: https://i.sstatic.net/61k5Z.png While this works fine on ...

Using jQuery UI to dynamically add a widget based on a specific class, rather than relying on

Exploring the world of Apache Cordova and jQueryUI is a new adventure for me. I am currently experimenting with formatting the layout of my index.html using jQueryUI. As mentioned in this section of the jQueryUI tutorial, a widget can be added using the f ...

Undo a CSS transition when clicked

There is a div named learn-more which expands to fill the whole page when a CSS class is added like this: .learn-more{ padding:10px; font-size: 20px; text-align: center; margin-top:20px; font-family: klight; -webkit-transition:2s; ...

What is the best way to prevent right floated DIVs from interfering with each other's positioning, specifically within a specified space?

Despite feeling like this question may have been asked numerous times before, I've searched high and low for an answer to no avail - both here and on Google. My HTML page has a maximum width that limits the size of the content. This content includes ...

Images that adapt to various sizes while maintaining a consistent visual hierarchy

Hey there, I'm struggling to achieve the same row size of images as shown in the example. However, when I adjust the window size, the larger images become smaller than the columns on the left. This has been a challenge for me and I haven't found ...

Utilizing jQuery to dynamically add classes

I am looking to dynamically add a date picker to input fields using jquery. It seems to be working fine for the first text field, but as soon as I add additional fields, it stops working. Any suggestions on how I can fix this? Thank you in advance. <ta ...

Utilize the display flex property within a nested flex container

I can't seem to get my link text centered both vertically and horizontally, it keeps aligning to the left. I was under the impression that using flex-based alignments would solve this issue. I have gone through the information on using a flex item as ...

Unable to show the name of the chosen file

After customizing the input [type = file], I successfully transformed it into a button with a vibrant green background. Here is the code snippet that enabled this transformation: <style> #file { height:0px; opacity:0; } ...

What is the best way to modify the size of a canvas element while maintaining effectiveness?

I've encountered an issue while using Canvas to create a pie chart with chart.js. Despite adjusting the dimensions of the canvas element, it continues to take up the entire page. <canvas id="myChart" height ="200" width="200"></can ...

Upon selecting multiple checkboxes, corresponding form fields will be displayed based on shared attributes

When multiple checkboxes are selected by the user, corresponding form fields should appear based on the checkboxes. For example, if both flight and hotel checkboxes are checked, then the full name and last name fields should be displayed while other fields ...

Web Development: Custom Search Form

I am looking to create a website with a form similar to this one, but I'm struggling to figure out how to incorporate all three components into a single form using only HTML and CSS - no javascript. Do you have any suggestions or advice on how to achi ...

Animated the height of a rectangle during initial loading and when the mouse hovers over or leaves

Being new to Vue.js, I am looking to create a simple animation on component load for the first time. You can find my initial code here: <template> <div id="app"> <div class="rect" /> </div> </template ...

Encountering a JavaScript error due to an erroneous character when trying to parse

I need to convert a `json` string into an object format that is extracted from a `.js` file. Here is the `JSON` string located in `document.js`: [ { "type": "TableShape", "id": "63c0f27a-716e-804c-6873-cd99b945b63f", "x": 80, ...

How can I center one middle position for my inputs and have the span align to the left?

How can I center my input fields with all the spans aligned to the left? I would like the inputs to be centered on the page, with supporting spans aligned to the left or right of the input lane. I am utilizing some Bootstrap 4 classes for this layout. C ...

What is the method for aligning a button label to the left and an icon to the right?

I have a list of items and I want to display label text on the left and a check icon on the right. This works fine when the text is short, but when I added the textOverflow property, the icon gets hidden along with the rest of the text. Here is my list ...