What are some tips for improving the smoothness and efficiency of my CSS @keyframes animation on SVG elements specifically in Firefox?

I noticed that this particular animation is causing high CPU usage on all browsers, although it runs more smoothly in Chromium. Is there a way to optimize its performance? Here's the SCSS code which is relatively simple:

@keyframes laptop {
  from {
    transform: rotate(0deg) translateX(0.8rem) rotate(0deg);
  }

  to {
    transform: rotate(360deg) translateX(0.8rem) rotate(-360deg);
  }
}

@keyframes phone {
  from {
    transform: rotate(0deg) translateX(0.8rem) rotate(0deg);
  }

  to {
    transform: rotate(-360deg) translateX(0.8rem) rotate(360deg);
  }
}

.header {
  &__laptop {
    animation: laptop 12s linear infinite;
    will-change: transform;
  }

  &__phone {
    animation: phone 8s linear infinite;
    will-change: transform;
  }
}

Answer №1

Since the animations are continuously looping, they naturally consume a significant amount of resources.

To alleviate this burden on the CPU, you can create an illusion of acceleration by transforming the animation into 3D. One way to do this is by adding translateZ(0) to the keyframes.

For instance, you could try something like the following:

 @keyframes laptop {
  from {
    transform: rotate(0deg) translateX(0.8rem) translateZ(0) rotate(0deg);
  }

  to {
    transform: rotate(360deg) translateX(0.8rem) translateZ(0) rotate(-360deg);
  }
}

@keyframes phone {
  from {
    transform: rotate(0deg) translateX(0.8rem) translateZ(0) rotate(0deg);
  }

  to {
    transform: rotate(-360deg) translateX(0.8rem) translateZ(0) rotate(360deg);
  }
}

.header {
  &__laptop {
    animation: laptop 12s linear infinite;
    will-change: transform;
  }

  &__phone {
    animation: phone 8s linear infinite;
    will-change: transform;
  }
}

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

Is there a way to make divs expand on top of existing content when hovering over them, in order to avoid needing to scroll through overflow content? I am currently working with

I am working with 9 boxes contained within divs, each box includes data that exceeds the size of the box itself (represented by Some Text repeated for demonstration purposes). I am seeking a solution where hovering over any box will cause it to enlarge and ...

Utilize React Styled Components to seamlessly unify the styles of two different components

I want to have consistent styles for both a styled input element and a styled select element. Currently, I accomplish this using string interpolation: const styles = ` background-color: white; width: 100%; border: 0 solid transparent; bor ...

What is the best way to smoothly move a fixed-size div from one container to another during a re-render process?

Introduction Anticipated change Similar, though not identical to my scenario: Situation 0: Imagine you have a container (chessboard with divs for game pieces) and a dead-pieces-view (container for defeated pieces). The positioning of these containers i ...

Changing Background Images Based on Screen Size in CSS Media Queries

Hey there, I am currently using two different header images - one for desktop and another for both tablet and mobile devices. I am wondering how I can automatically switch from the desktop header image to the mobile/tablet header image when the screen siz ...

Enhance your webpage with dynamic styling using third-party CSS animation

Apologies for any similarity to other questions on this topic. I have searched extensively, but any assistance would be greatly appreciated. I am utilizing a new animation library from Animista to animate specific elements on a test website. Animating ele ...

Update background to full screen and include text when hovering over DIV

Currently, I am utilizing Bootstrap and have a layout with 6 columns containing icons/text within. I desire to implement a hover effect where each column triggers a background change in transition for the entire section. In addition, text and button elemen ...

The image in the HTML is currently positioned at the bottom, but I would like it to be

this is what it looks like: https://i.sstatic.net/VLqN7.png I need it to be at the top next to the first card. <!-- top nav--> <nav class="navbar navbar-expand-lg navbar-light" style="background-color:white"> <a class="navbar-brand" ...

Struggling with determining the perfect transition speed for the sidemenu display

I'm a newcomer to web development and facing an issue with setting the transition speed for opening and closing this side menu. Despite adding transitions in the CSS and specifying duration in the Javascript, the menu continues to open instantly. I di ...

Comparing Yii's CHtml::link() function with the use of regular <a href=''></a> HTML tags

When using elements like yii CHtml::link, what are the recommended practices? I'm working on a button that needs to include an icon, text, respond to hover events, and be wide. Are there any benefits to using CHtml instead of a regular tag that can e ...

No space left around the image's border

Whenever I apply a border to an image, it comes with a margin and the image itself receives white padding. How can I remove the margin from the border? This is how I currently have it: border: 1px solid gray; ...

Text within the div element causes the displacement of other adjacent div elements

When the text in mondaySpecial extends to a second line, it pushes tuesdaySpecial-saturdaySpecial further down on the page, disrupting the layout of the divs. The same issue occurs with other specials as well. Is there a way to prevent this from happening? ...

I am interested in implementing a feature that automatically saves form data when changes are made. My solution involves creating a dynamic form utilizing

When creating a dynamic form in HTML using Laravel and then calling it through JQuery, I encountered an issue where the first form created showed an undefined form ID, but subsequent forms displayed their form IDs. How can this issue be resolved? Below i ...

Align elements vertically with React-Bootstrap by using the built-in functionality for center

Struggling to vertically center and center align elements using bootstrap, even with react-bootstrap col and row components. You can view my code on Codesandbox: Link Here is the code snippet: import React, { PureComponent } from "react"; impo ...

Unexpected behavior from flexbox layout

So I've been experimenting with Chrome lately. I created a div with display: -webkit-box;. Inside this div, there are 7 other divs all set to -webkit-box-flex: 1;. Oddly enough, the first div is smaller than the rest. Any ideas on why this might be ...

What is the best way to retrieve the value of a chosen option utilizing Javascript or Jquery?

I have been working on a custom select box and I am trying to retrieve the value of the selected label. When I click the "check" button, an alert pops up showing the code inside the div, which makes sense. However, I am wondering how I can extract the valu ...

Place a locator on the variable at the identical level

My objective is to locate an element with both an id and a class. I achieve this using the following code snippet: return element(by.css('#right.closed')).isPresent(); While this method works correctly, I am looking to enhance it by introducing ...

use angularjs directive to position a div absolutely aligned with the right edge of another div

I am attempting to use an angularjs directive to align the right side of an absolute div with another div. The code is working, but I am encountering an issue where the children divs are slightly wider than their parent, causing the offsetWidth value to be ...

Excess background spills beyond the width of the window

Looking to create a design similar to the following: A main container with 'n' child elements that may extend beyond the width of the window, causing the page to scroll horizontally instead of wrapping to the next line. This main container ...

The persistent Bulma dropdown glitch that refuses to close

In the project I'm working on, I have implemented a Bulma dropdown. While the dropdown functions correctly, I am facing an issue when adding multiple dropdowns in different columns with backend integration. When one dropdown is open and another is cli ...

Progress bar display not available

I have recently developed a JavaScript quiz application and included a progress bar feature. While it works flawlessly offline on my laptop, I encountered an issue when uploading the files to Codepen.io - the progress bar fails to display. I would appreci ...