Tips for creating a dynamic animation: How to make a div fall from the top and rotate

Hey everyone, I'm working on creating an animation where a phone falls from the top and then rotates and skews to give the illusion of a 3D shape when it reaches the bottom. However, I'm facing an issue with flickering in the animation when it hits 100% keyframes. Can anyone share some tips, tricks, or examples on how to achieve this smoothly? Thank you in advance! Below is the code I've been using:

<!DOCTYPE html>
<html>
<head>
    <title></title>
  <script defer src="brands.js"></script>
  <script defer src="solid.js"></script>
  <script defer src="fontawesome.js"></script>
   <!-- Rest of the HTML content goes here -->
  
</body>
</html>

Answer №1

If you want to achieve a specific effect, consider utilizing the CSS rotate3d function for easier implementation.

To simulate the rotation of an inclined object, use

transform: rotate3d(-0.3, 1, 0, 390deg)
:

div {
  position: absolute;
  background-color: red;
  height: 240px;
  width: 150px;
  border-radius: 3px;
  transform: rotate3d(-0.3, 1, 0, 30deg);
  animation: rotate 1s infinite;
}

@-webkit-keyframes rotate {
  100% {
    transform: rotate3d(-0.3, 1, 0, 390deg); /* 405 = 360 + 45 */
  }
}
<div></div>

To create the falling animation, add it in your design to give the impression of a phone falling on the ground:

body {
  height: 350px;
  position: relative;
}

div {
  position: absolute;
  background-color: red;
  height: 240px;
  width: 150px;
  top: 0%;
  border-radius: 3px;
  transform: rotate3d(-0.3, 1, 0, 30deg);
  animation: fall 1s infinite;
}

@-webkit-keyframes fall {
  25% {
    top: calc(100% - 240px);
    transform: rotate3d(-0.3, 1, 0, 45deg);
  }
  100% {
    top: calc(100% - 240px);
    transform: rotate3d(-0.3, 1, 0, 405deg);
    /* 405 = 360 + 45 */
  }
}
<div>
  <p>
    Example text...
  </p>
</div>

Answer №2

To avoid any jank in the animation, it is important to define all animation values for each keyframe. Omitting rotation and skew values in certain keyframes can lead to performance issues.

<!DOCTYPE html>
<html>
<head>
    <title></title>
  <script defer src="brands.js"></script>
  <script defer src="solid.js"></script>
  <script defer src="fontawesome.js"></script>
    <style type="text/css">
        .phone{
            width: 600px;
            height: 1080px;
            background-color: black;
            border-radius: 9%;
            margin: 50% auto;
            position: relative;
            animation: bounce 2s ease-in-out forwards;
        }

        @keyframes bounce {
          0% { transform: translateY(-500px) rotate(0) skew(0, 0); }
          50% { transform: translateY(0) rotate(0) skew(0, 0); }
          70% { transform: translateY(-200px) rotate(0) skew(0, 0); }
          100% {
            transform: translateY(-50px) rotate(30deg) skew(5deg, 347deg);
          }
        }
    </style>
</head>
<body>
    <div class="phone">
        <div class="inner-phone">
            <div class="inner-screen">
                <div class="chat-screen">
                    <div class="container-chat">
                        <div class="chat-item ci1">
                            <div id="wrapper">
                              <div class="chat">
                                <div class="chat-container">
                                  <div class="chat-listcontainer">

                                    <ul class="chat-message-list">
                                    </ul>

                                  </div>
                                </div>
                              </div>
                            </div>
                        </div>
                        <div class="chat-item ci2"> 
                        </div>
                        <div class="chat-item ci3">
                        </div>
                        <div class="chat-item ci4">
                        </div>
                        <div class="chat-item ci5">
                        </div>                                  
                    </div>
                </div>
                <div class="rich-message">
                </div>
            </div>
        </div>
        <div class="phone-drop-shadow"></div>
    </div>
    <div class="portal-phone">
        
    </div>
</body>
</html>

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

Bootstrap CSS: arranging columns for mobile devices

UPDATE: Having implemented the solution provided in the accepted answer below, I find myself back at square one with the original layout before any adjustments were made. The issue still remains unresolved. Any advice on how to achieve the desired design o ...

Tips for updating mysql records on a web page without the need to refresh it using PHP

Consider this situation: Below is the code that shows all user accounts. <table border="3px" align="center" cellspacing="3px" cellpadding="3px"> <tr> <td>Username</td> <td>Password</td> <td><a href="" oncli ...

Angular unable to find a route for external links

I am attempting to create an external link with an <a href="google.com"></a>, but for some reason it redirects me to localhost:4200/google.com... I'm not sure why this is happening, but I need to eliminate the localhost:4200. Below is the ...

Create a minimalist Vue table design that enforces a maximum of 2 or 3 columns within

Is there a way to make my v-simple table with v-chips and v-badges align correctly in two or three column peer cell format? Here is the table for reference: https://i.sstatic.net/OFCyx.png Currently, I only have scoped styling applied: <style scoped> ...

Achieve horizontal wrapping of div elements

Currently, I am developing a blog where search results for articles will be displayed within divs. The design of the website is completely horizontal, meaning that articles scroll horizontally. Creating a single line of divs is straightforward, but it&apo ...

What is the best way to position <div> elements?

I'm having trouble aligning two elements to create columns and adding a footer. Currently, the elements are stacked horizontally and the footer is inline with them. How can I adjust the formatting of the page? h1 { color: #225522; margin: 0px ...

What is the best way to choose the initial and final <td> that appears within a <tr>?

I am working with an html table that has the following structure: <table> <tbody> <tr> <input type="hidden" name="a" value="x"> <input type="hidden" name="b" value="y"> <td>First Ce ...

What is the best method for resizing an SVG according to the size of my website's window?

I am attempting to implement a scalable settings icon SVG file that adjusts based on the window width. My approach involved creating a JavaScript function that alters the element's dimensions according to the window size, but unfortunately, this metho ...

What is the best way to update JSON data using JQuery?

I apologize for posing a seemingly simple query, but my understanding of JavaScript and JQuery is still in its early stages. The predicament I currently face involves retrieving JSON data from an external server where the information undergoes frequent ch ...

When using jQuery to focus on an input element, the cursor fails to show up

Looking to enhance user experience by focusing on an input element upon clicking a specific div. The HTML structure being used is as follows: <div class="placeholder_input"> <input type="text" id="username" maxlength="100" /> <div ...

Truncate a string in Kendo Grid without any white spaces

While using a Kendo-Grid for filtering, I've come across an issue where my cell does not display the full string if there is no white space. The problem can be seen in the image below: https://i.sstatic.net/0h1Sg.png For example, the string "https:/ ...

Compatibility Issue between Jquery UI CheckBox Button and Click Function in IE8

Situation: After calling addButton() function in jQuery, the checkbox element is successfully turning into a button. However, the click event that should trigger an alert message is not functioning. This issue seems to be specific to IE-8 compatibility. ...

When an input is double-clicked, the message"[object object]" appears on the screen

Here is the structure of the template used for the directive. Our code fetches data from a service which contains all the details of a specific individual. We display only the first name, last name, and either designation or company affiliation from that d ...

Establish the lowest possible height for Angular Material Expansion Panel Content

Is there a way to specify a minimum height for the content of an Angular Material expansion panel when it is open? I have searched for examples on setting the expandedHeight and collapsedHeight for the header, but not for the content itself. The Angular Do ...

Enabling the upload of .sql files in a file input field

I'm working on a file input field that I want to restrict to only accept XML, SQL, and text files. Here's the code snippet I have implemented so far: <input type="file" name="Input_SQL" id="Input_SQL" value="" accept="text/plain,application/x ...

The CSS filter "progid:DXImageTransform.Microsoft.Alpha(style=1,opacity=80)" is not functioning properly in Firefox

Trying to apply a filter effect using CSS but encountering issues in Firefox: progid:DXImageTransform.Microsoft.Alpha(style=1,opacity=80 ) opacity: 0.5; -moz-opacity: 0.5; Any s ...

Implement a customized toString method for components in ReactJS

Looking to modify the toString method of a class component in reactjs? Check out the code snippet below class C1 extends React.Component{ render(){ return ( <div> {C2.toString()} </div> ) } } class C2 extend ...

What is the correct CSS2 selector syntax to apply the :hover effect to the nth child of a specific element?

My goal is to apply a unique background color to each menu li element when hovered over, and I want to accomplish this using CSS2. <ul> <li> <li> <li> <li> </ul> I managed to add a background color to t ...

The navigation and title refuse to align in the center

Learning coding from scratch is a challenge, especially when tasked with creating a website for school. Right now, I'm gradually getting the hang of it, but I am struggling to center my navigation and title. Everything looks fine on my 13-inch laptop, ...

Displaying text on an image when hovering over it

I have tried various solutions that I came across, but none of them have been successful so far. My goal is to display dynamic text over an image when the user hovers over it. Additionally, I would like to change the hover color. Currently, the text is alw ...