Animate with keyframes: slide first, then rotate

I want to add a unique touch to my text by sliding it in and creating a bouncing effect as if it's hitting a wall before settling into place.

However, the issue I'm encountering is that whenever I incorporate rotation, the text rotates while still in motion instead of rotating once it has reached a certain point.

To clarify - I am looking for the div to start rotating once it hits -30px, then return to its original position without rotation, change direction, and finally settle into place.

Below is the current CSS code I am using...

@-webkit-keyframes slide {
from {right: 1500px; -webkit-transform: rotate(0deg)} 
50% {right: -30px; -webkit-transform:rotate(5deg)} 
75% { right: 20px} 
to {right: 0px}
}

div {
-webkit-animation: slide 5s;
}

Answer №1

Transitioning smoothly from one point to another involves a gradual animation process. To initiate the animation at 50%, you must distinctly define it as starting at 0 degrees, reaching 50%, then transitioning to 5 degrees, and finally reverting back to 0 degrees later on. Here is the code snippet that aligns with your requirements:

@-webkit-keyframes slide {
0% {right: 1500px;} 
50% {right: -30px; -webkit-transform:rotate(0deg)} 
55% {right: -30px; -webkit-transform:rotate(5deg)}
65% {right: -30px; -webkit-transform:rotate(0deg)}
75% { right: 20px} 
100% {right: 0px}
}

div {
-webkit-animation: slide 5s;
}

It's crucial to note the repetition of "right: -30px;" three times in the code. Without this repetition, the animation would proceed to the subsequent specified value, initiating an animation shift to a positive 20px.

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

Join and authenticate

Currently, I am facing a rather peculiar issue. I have created a simple login form that seems to be functional halfway. Users can input their name and other details, but upon clicking the Submit button, I encounter an error stating "Undefined index: nameX" ...

What is the best way to arrange four HTML elements in two rows, with two elements on each row?

I'm trying to figure out a way to display a phone icon and number on one line, as well as an email icon and address on another line. body { font-family: 'Open Sans', sans-serif; background: #20b2aa; } h1 { font-size: 40px; color: ...

Tips for sharing a React component with CSS modules that is compatible with both ES Modules and CommonJs for CSS modules integration

Some frameworks, like Gatsby version 3 and above, import CSS modules as ES modules by default: import { class1, class2 } from 'styles.modules.css' // or import * as styles from 'styles.modules.css' However, other projects, such as Crea ...

Troubleshooting a malfunction in Bootstrap dropdown due to conflicting inner CSS styles

I created a header with bootstrap, but I noticed a glitch in the dropdown menu when I added an internal stylesheet for other elements on the same page. Even adding the Bootstrap CDN or jQuery CDN links did not resolve the issue. The header functions proper ...

Utilize AJAX to parse an HTML Table retrieved from an ASP page and extract targeted cell data

Within our work intranet, there exists an ASP page that retrieves data from a variety of sensors. This data is organized in a table format with multiple rows and columns. It struck me as interesting to showcase some of these outputs on our department&apos ...

using CSS to position elements that are generated dynamically

Hey there, I'm facing a little issue with my elements. These elements are being generated dynamically and I'd like to display them in a 4 column layout. The challenge is that they arrive separately and I can't simply wrap them in a div and u ...

Using jQuery to select the next table cell vertically

Is there a way to utilize jQuery to access the cell (td) directly below a given cell in a traditional grid-layout HTML table (where each cell spans only one row and column)? I understand that the code below will assign nextCell to the cell immediately to ...

The website functions well in responsive design mode on an iPad screen, but encounters issues when viewed on an actual

The website is functioning well in responsive design mode on an iPad screen, however it seems to be having some issues specifically on iPad devices. I have tested it on all other devices and it works perfectly fine, but for some reason not on iPads. Feel ...

Maintain the grouping of elements within a div when printing in Internet Explorer 8

When printing in IE8, I'm facing an issue with keeping the "Table title" line on the same page as the <table>. Despite using page-break-inside:avoid;, there is still a page break between the table title and the actual table. My expectation is f ...

Prevent scrolling while popup is open

I found a helpful tutorial online for creating a jQuery popup (). However, due to my limited understanding of jQuery, I'm having trouble getting it to meet my needs. The issues I'm facing are: I need to prevent the webpage from scrolling when ...

Error TS7053 occurs when an element is given an 'any' type because a 'string' expression is being used to index an 'Object' type

When attempting to post data directly using templateDrivenForm and retrieve data from Firebase, I encountered the following type error message. Here are the relevant parts of my code: // Posting data directly using submitButton from templateDrivenForm onC ...

Is there a way to align the content in my Flexbox rows to the top of each cell, resembling a table layout?

I am currently facing challenges in aligning my layout correctly, especially on resolving the final adjustments. In the scenario described below, everything seems to work fine when the message_data <span> elements contain a single line of data. Howe ...

The positioning of a div element is not functioning as expected

I am currently updating my portfolio project. The page I am working on includes an image with a specific date displayed on it. I want to add text below the image, but I am encountering some issues: The text I want to include is meant to be a link, like th ...

Export Image as Json File

I am currently working on creating a browser extension and I am trying to figure out how to save images locally. My plan is to store the images in a json file, but I'm feeling quite lost on how to accomplish this. Below is the code I have so far, alth ...

Modify the color of the 'li' element that shares the same attribute value as the current page

I am in the process of creating a website for an architecture company. Currently, I am working on a specific page which you can find here: . Each project falls into a category such as residential, commercial, or education. On each project page, I include t ...

How can I turn off bi-directional data binding in Angular?

Utilizing Angular Material's md-dialog, when the user clicks the "edit" button to display the dialog, it takes the current object (a table row) and sends it to the function showDialog, populating the dialog fields with its values: <button ng-class ...

Is there a way to position a div on top of the header with flexbox?

I am a beginner in the world of coding and I am currently experimenting with flexbox to create the layout for my website. However, I am facing a challenge where I need to overlay some text and an image on top of the pink rectangular section that is part of ...

Place a picture and words within a submit button

I need assistance with aligning text and a small airplane image on a submit button. Currently, the text is overlapping the image and I am unsure how to fix this issue. How can I adjust the position of the text to display to the right of the button? Is ther ...

Pattern to locate a CSS class identifier

I've been working on creating a regex to match valid CSS class name structures. Currently, my progress looks like this: $pattern = "([A-Za-z]*\.[A-Za-z]+\s*{)"; $regex = preg_match_all($pattern, $html, $matches); However, there are certai ...