Improving the performance of a graphics card-intensive animation frame

With appreciation to @Temani Afif, we were able to implement this stunning frame. Despite the code operating smoothly, an issue has arisen that renders the code ineffective.

A staggering 90 percent of my GPU resources are being utilized! Within just 10 seconds of activation, my laptop begins overheating!

Why is this occurring and how can it be resolved?

UPDATE: It appears that the problem lies in the code continuously rendering the animation behind the image; if you comment out addimage(), this becomes evident.

You can test this yourself: Please Run the code in CodePen

Below is the code snippet: (An image is inserted onto the page using the addimage() function, with all other elements being CSS and HTML)

addimage(); 
function addimage() {

  let pictureSource = 'https://www.architectureartdesigns.com/wp-content/uploads/2013/03/ArchitectureArtdesigns-8.jpg';

  var node = document.getElementsByClassName('content');
  node[0].style.background = 'url("' + pictureSource + '") center/cover'

}
body {
  height: 100vh;
  margin:0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: black;
}

.box {  
 border-radius: 10px;
  background: 
    repeating-linear-gradient(-45deg, white 0 7.5px, hotpink 0 15px) 
    0 0/21.21px 21.21px;  /* 21.21px = sqrt(2) * 15px */
  animation: animate 1s linear infinite;
}

.box .content {
  width: calc(90vw - 30px);
  height: calc(85vh - 30px);  
  border-radius: 10px;
  box-shadow: 0 0 2px deeppink, 0 0 5px rgba(0, 0, 0, 1), inset 0 0 5px rgba(0, 0, 0, 1);
  margin:15px;
}


@keyframes animate {
  to {
    background-position: 21.21px 21.21px; 
  }
}
<div class="box">
  <div class="content">

  </div>
</div>

Answer №1

In my opinion, using background-position for animation can be quite costly. I suggest trying the code below to see if it works properly. Instead of utilizing background-position, I have opted to use the transform property for animation.

addimage(); 
function addimage() {

  let pictureSource = 'https://www.architectureartdesigns.com/wp-content/uploads/2013/03/ArchitectureArtdesigns-8.jpg';

  var node = document.getElementsByClassName('content');
  node[0].style.background = 'url("' + pictureSource + '") center/cover'

}
body {
  height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: gray;
}

.box {
  border-radius: 10px;
  position: relative;
  overflow: hidden;
}
.box::after {
    content: '';
    position: absolute;
    z-index: -1;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background:
      repeating-linear-gradient(-45deg, white 0 7.5px, hotpink 0 15px) 0 0/21.21px 21.21px;

    width: calc(100% + 21.21px);
    height: calc(100% + 21.21px);
    transform: translate(-21.21px, -21.21px);
    /* transform: translate(-15px, -15px); */
    /* transform: translate(0, 0); */
    animation: animate 1s linear infinite;


  }
.box .content {
  width: calc(90vw - 30px);
  height: calc(85vh - 30px);
  border-radius: 10px;
  box-shadow: 0 0 2px deeppink, 0 0 5px rgba(0, 0, 0, 1), inset 0 0 5px rgba(0, 0, 0, 1);
  margin: 15px;
}


@keyframes animate {
  to {
    /*     background-position: 21.21px 21.21px;  */
    transform: translate(0, 0);
  }
}
<div class="box">
  <div class="content">

  </div>
</div>

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

Determine whether to create or update with a Node.js API

I have developed a nodejs API where users can add new entries by sending a POST request. If the entry already exists, it should be updated. However, I am facing an issue with the findOne() method from mongoose not triggering the update function as expecte ...

The route for ` http://localhost/admin/` seems to be experiencing issues, however, it functions correctly when accessed through

Greetings everyone! Currently, I am diligently working on a project using AngularJS. Everything runs smoothly when accessing the project through this route: http://localhost/. However, I encounter an issue with the admin panel link: //localhost/admin/. I ...

Storing Form Images in MongoDB with Multer in NodeJS and Sending as Email Attachment

I have been working on a website that allows users to input details and attach images or PDF files (each less than 5MB) to the form. My goal was to store the entire image in my MongoDB database and also send it to my email using Nodemailer in Node.js. Whi ...

How to use jQuery to update the href attribute of a parent link

Can someone help me figure out why I am having trouble changing the 'href' of the parent link to a header logo? Thank you in advance! Here is the HTML code snippet: <a href="https://URL.IWANTO.CHANGE"> <img id="partner_logo" src="/ ...

Header formatting issue when attempting to implement tablesorter plugin

I implemented the widget-scroller and widget column Selector in my table using the table sorter plugin in jQuery. Has anyone encountered a problem like the one shown in this picture? It seems that my table headers do not align with the columns properly an ...

Ensuring AngularJS ui-router/app waits for $http data to avoid Flash of Unstyled Content (FOUC)

My question or situation pertains to the states defined in my AngularJS application. Here is an example of how I have them structured: $stateProvider .state('myApp', { abstract: true, template: '& ...

The HTML retrieved cannot be accessed by external JavaScript code

I've encountered a major issue. I'm using ajax to retrieve content in HTML format, but my main JavaScript file is unable to manipulate any retrieved elements - tags, classes, IDs, you name it. Is this normal? How can I work with the data once it& ...

Use the JavaScript executor to combine a dynamic string

I have a String variable that retrieves IDs from an Excel sheet. String id = formatter.formatCellValue(sheet.getRow(i).getCell(2)); I am trying to dynamically update the ID using JavaScript executor, but it seems that the concatenation is not working cor ...

When the checkbox is not selected, the associated field values will be submitted in AngularJS

I am facing an issue with a checkbox that, when checked, reveals two fields (a select tag and a textbox). In addition, I have a multiselect input field. The requirement is that at least one of these fields (either the checkbox or the multiselect input) mus ...

JavaScript can be utilized to monitor outbound clicks effectively

I am currently working on implementing the code found at this link: Make a ping to a url without redirecting. The original poster is looking to ping a URL without opening multiple windows. My goal is to achieve the same functionality, but I also want to vi ...

Can Hapi-Joi validate a payload consisting of either an Array of objects or a plain Javascript object?

How can I create a schema to validate payloads for a post call that accepts either a single JS object or an array of objects to be saved in the database? JS object { label: 'label', key: 'key', help_text: 'text' } ...

Utilizing AJAX to Load JSON File Compressed with GZIP

I utilized the gzip algorithm to compress a JSON file, following this method (source: java gzip can't keep original file's extension name) private static boolean compress(String inputFileName, String targetFileName){ boolean compressResu ...

What is the most efficient way to manage form field errors using a single function in ReactJS?

I am facing a challenge with a form that requires users to answer three questions in order to register a new password. All fields must be filled out, and the user cannot submit the data to the server until all three questions are answered. My concern is h ...

What is the best way to ensure a floated div fills up the rest of the available horizontal

Apologies for the unclear title of my issue. I struggled to find the right words to describe it while searching for a solution. I have fixed-size divs that need to be floated left and behave like inline blocks. On the right side of the page, there is a co ...

make the width of the table cell as compact as can be

I have a table that spans 100% of the width, and I'm wondering how I can set the width of columns 2 and 3 to be as small as possible without causing the content to break. I tried adding a specific width style, but I know this is not recommended for r ...

Tips for including information in a chart

I'm facing an issue with my current code as it is not functioning properly. Here is the link to the current output: http://jsfiddle.net/4GP2h/50/ ...

Is there an issue with the way I've implemented my depth-first search algorithm?

After implementing a dfs search for an 8 puzzle game, I have encountered an issue where my stack keeps adding possible movements without decreasing to find an answer. It seems like the code is not working correctly as a dfs should be, and I'm seeking ...

Surprising outcome from the glob-fs glob.readdirSync function

Below is some nodejs code that I am working with. The client initially calls /api/demosounds and then calls /api/testsounds. var glob = require('glob-fs')({ gitignore: true }); app.get('/api/demosounds',function(req,res){ var d ...

Adding functions to the window scroll event

Rather than constantly invoking the handler, John Resig proposes using setInterval() to optimize the number of times it is called - check out his thoughts at http://ejohn.org/blog/learning-from-twitter/ In his blog post, John presents the following soluti ...

How to Utilize Class Members in a Callback Function in Angular 12 with Capacitor Version 3

When I click the "Device Hardware Back Button" using Capacitor 3.0, I'm trying to navigate to the parent component with the code below. The device back button is working correctly, but I'm facing an issue where I can't access class members i ...