Using transform in CSS animations may cause unexpected behavior

There seems to be a strange issue in Chrome with the animation I created. It moves to the left first before reaching the intended position.

The animation should only move to the right and top directions.

Css

.intro .cogFade .cog {
    position: absolute;
}

.cog.large {
     animation-name: cog-large;
 }

@-webkit-keyframes cog-large {
  100% {
    position: absolute;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -40%) scale(1, 1);
  } 
}

Html

<div class="intro">
        <div class="cogFade">
            <div class="cogElements" style="margin-top: 194px;">
                 <div class="circle zoomout" style="margin-top: 194px;"></div>
                 <div style="font-size: 5rem;" class="cog large">
                     <i class="icon-cog spinning"></i>
                 </div>
            </div>
        </div>
        <div style="font-size: 15rem; display: none;" class="b breathing">
              <i class="icon-dotb"></i>
        </div>
 </div>

Please watch the animation here: http://jsfiddle.net/hutber/fejpm491/1/

Answer №1

I took the code you provided and placed it in a JSFiddle since the original link you shared was too large to manage.

It's worth noting that the -webkit- prefix is no longer necessary for animations in Chrome.

The issue lies in the fact that there are missing initial values for position, left, and top, resulting in an animation that is not fully defined. This causes browsers to render the animation differently, hence why it appears different in Chrome and Firefox.

To resolve this, ensure that position: absolute always remains true regardless of the animation, and then set appropriate start and end values for left and top.

Here's an example based on your code

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

How can I prevent the content on my page from adding padding to the body of the page?

I'm working on designing a simple interface similar to Slack. However, I'm facing an issue where the left navigation is creating some padding from the body, even though I have set the padding and margin to zero. .app { display: flex; flex- ...

Is it achievable to use multi-level :not selectors in CSS / JS querySelector?

I have come across numerous tutorials explaining the use of multiple :not selectors on a single element. However, I have yet to find any examples of using :not selectors on different levels within a single CSS / JS querySelector path. For instance, conside ...

Display information from a database table in a structured layout using row and column identifiers

I am working with a Postgre SQL database table structured like this: Row_no Col_no Name 1 1 Test 1 2 Result 1 3 Observation 2 1 abc 2 2 Result1 2 3 observation1 My goal is to d ...

PHP Email Styling Techniques

While working on a website, I encountered an issue with the automated email sent upon registration. The email was displaying the CSS code. $body '<span style="color:#444444;">Header</span>'; I attempted to use a code from online tha ...

How to Show an Image in a Search Bar Using HTML

As I put the finishing touches on this table, I decided to add a search function to it. However, I encountered an issue with the search bar design. I wanted to incorporate a search icon png file as the background image, similar to the example showcased on ...

Best sizes for Media Queries to target tablets, smartphones, laptops, and desktops

What are the optimal Media Query sizes for effectively targeting tablets, phones, laptops, and desktops? For instance, considering that both the iPhone and Droid feature a screen size of 320X480, it is important to ensure that your design looks good at th ...

The Challenges of Parsing HTML Source Code for Web Scraping

I've been attempting to scrape data from this website: (specifically rare earth material prices) using Python and BeautifulSoup. My query pertains not to Python, but rather the HTML source code of the site. When I utilize Firefox's "Inspect Elem ...

Joomla's erroneous media directory path leads to prolonged loading times

We seem to be facing an issue with a Joomla! 3.1 website at the following URL: There are two CSS files being included incorrectly: <link rel="stylesheet" href="//media/jui/css/bootstrap.min.css" type="text/css" /> <link rel="stylesheet" href="// ...

Tips for limiting the size of image uploads to under 2 megabytes

I am trying to implement an html select feature that allows users to upload images. <div class="row smallMargin"> <div class="col-sm-6"> Attach Image </div> <div class="col-sm-6"> <input type="file" ng-model="image" accept=" ...

Submitting user inputs from an HTML form into a MySQL database using PHP

I've successfully put together an HTML form that is meant to capture user input data and insert it directly into a table within mySQL. newuser.php file <?php //including the connection page include('./DB_Connect.php'); //create a n ...

HTML Elements for Displaying Undefined JSON Information

Hey there, I'm new to programming and I'm looking to display JSON data in an HTML table using jQuery. The issue I'm facing is that the output from the server shows up as 'undefined'. My goal is to have a constantly updated list of ...

Locate the XPath for text that is within a div tag and adjacent to a span tag

I've searched, but couldn't find an exact match, so my question is about a low HTML code: <div class="column1"> <div> <div class="name"> Dynamic Name <span class="id" title="ID">Dynamic ID</span> </div> </d ...

Creating a unique logo effect with transparent borders that seamlessly blend into the background color of the div

https://i.sstatic.net/057Pk.png I have been experimenting with different approaches to design the white navigation menu that is supposed to span across the top of the image. However, I am struggling to make it scale gracefully in CSS. I am considering usi ...

Manipulating text on an image without using canvas, using vanilla JavaScript

I've been working on a project to create a meme generator without using canvas, as part of my DOM manipulation practice in vanilla JavaScript. I'm facing challenges in adding text to the user-submitted pictures and need some guidance in achieving ...

How to Access a PHP Variable within a JavaScript Function Argument

.php <?php $timeArray = [355,400,609,1000]; $differentTimeArray = [1,45,622, 923]; ?> <script type="text/javascript"> var i=0; var eventArray = []; function generateArray(arrayName){ eventVideoArray = <?php echo json_encode(arrayName); ...

The necessary attribute is malfunctioning. (HTML)

I am currently working on a signup page utilizing HTML and JavaScript. Everything was running smoothly until I added a function to navigate the user to the next page. The issue arises when the textboxes are left blank; upon clicking the button, the user is ...

Issue with Google Tag Manager where the class name is ending with '-ok' is causing problems

Utilizing Google Tag Manager for monitoring clicks within my search engine, which showcases various book details such as cover images, titles, and authors. When a book is in stock, it displays a checkmark and "Leverbaar" (In stock) below the price tag ($1 ...

The custom HTML menu implementation is causing the jQuery autocomplete to lose its "Select" functionality

Seeking assistance in implementing jQuery autocomplete with a custom drop down menu. I have managed to customize menu items using the data()._renderItem method (which is currently commented out), however, this approach disables the menu "Select" function ...

Transforming a Multi-Dimensional Array into an HTML Table

Experimenting with a new idea. I hope the solution is straightforward; I just can't seem to figure it out. Imagine I have an array like this: var items = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]; My goal is to rearrange the data so that it looks like t ...

Textarea with integrated checkbox

Can checkboxes be incorporated within a textarea using basic HTML and CSS? I'm aware that this can be achieved with tables, but I'm curious if it's possible within a textarea itself. ...