Endless Blinking Problem with Image Refreshing When Updating Data Using JQuery

I am working on developing an online game that features different items. However, I am facing a challenge with the images of these items blinking when the percentage value is updated. How can I resolve this issue?

Is there an alternative approach I could take by making changes to my HTML and CSS code?

Problem:

https://i.sstatic.net/TNKRA.gif

var percent = 0;

var countdown = setInterval(function () {
 percent++;
 $(".food_container > div").each(function(index, element) {  
    if(percent == 100){ clearInterval(countdown) }
    $(element).css({"--value": percent + "%"}).attr("data-value",percent + "%");
  });
}, 1000);
body{
      background-image: linear-gradient(to bottom, #35C10D, #6FE814);
      background-repeat: no-repeat;
      height: 100vh;
      font-family: 'Arial', sans-serif;
   
}
.food_container{
    display: flex;
    gap: 30px;
}
.food_container > div {
    background-image: var(--image-url);
    background-size: contain;
    background-position: center center;
    background-repeat: no-repeat;
    position: relative;
    display: flex;
    height: 60px;
    width: 60px;
    justify-content: center;
    align-items: center;
}

.food_container > div:before {
    content: attr(data-value);
    display: flex;
    justify-content: center;
    font-size: 9pt;
    align-items: end;
    position: absolute;
    bottom: -20px;
    left: 0;
    color: #fff;
    right: 0;
    height: calc(var(--value) + 20px);
    width: 100%;
    transition: .3s ease;
    box-shadow: 0 -7px 22px -7px rgb(255 255 255 / 12%), 0 -7px 5px -7px white;
    border-top: 1px solid rgb(255 255 255 / 58%);
    background-image: var(--image-url);
    background-size: 60px;
    background-position: center bottom 20px;
    background-repeat: no-repeat;
    filter: grayscale(1) brightness(1.2);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="food_container">

<div style="--value: 0%;--image-url: url(https://svgur.com/i/hrP.svg);" data-value="0%"></div>
<div style="--value: 0%;--image-url: url(https://svgur.com/i/hrm.svg);" data-value="0%"></div>
<div style="--value: 0%;--image-url: url(https://svgur.com/i/hrQ.svg);" data-value="0%"></div>


</div>

Answer №1

It turns out that my code was fine all along. The issue I encountered was actually caused by having the console (F12) open. I only realized this after some investigation.

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

Main view not displaying the updated MVC partial view

Need help updating my partial view within the main view after an ajax button click. I have checked the values in the model while stepping through the partial view, and they are correct. However, when I try to display the new values in the main view by stor ...

jQuery: Repeated Triggering of Button Click Event

At my website, I am facing an issue with multiple buttons being loaded twice via ajax from the same file. The problem arises when the event associated with a button fires twice if that same button is loaded twice. However, it functions correctly if only o ...

The jQuery Ajax call triggers a page refresh

I've searched high and low for a solution, but I just can't seem to figure it out. I have a simple jQuery code snippet below that successfully retrieves the IDs (array) of checkboxes and sends them to the report.php page using Ajax: $('#repo ...

Convert XML data into a structured table format

We have an XML file named "servers.xml" that needs to be parsed. This file is located on the same server where we want it to be parsed, in the same folder. <root> <list> <server> <server name="28 Disconnects La ...

Styling with Bootstrap 4 limited to the left column

My row is dynamically filled with X items contained in a col-3 class, depending on the screen size. Is it possible to easily style only the column that will appear on the left during screen resizing? For example: lg screen: https://i.sstatic.net/JSTpL.pn ...

Is there a method to identify if the dark theme is enabled in iBooks while working within an EPUB file?

Is there a specific code or feature that iBooks uses to enable the customization of certain sections within the book, such as changing to lighter colors when night mode is on? ...

What is the reason behind using AJAX to attempt sending a new URL request on

Having a strange issue with my product list. When trying to edit a product by clicking on it, I am redirected to the product form where an AJAX request is supposed to be sent to getFiltersGroup. However, on error, the AJAX request is somehow being sent to ...

Date Boxes in a Tangled Web

Looking to showcase multiple dates on a screen, I'm encountering an issue where clicking on a date button opens a datepicker. If the user clicks out of the box, the datepicker closes properly. However, when another datepicker button is clicked, instea ...

Tips for positioning an image in the TOP Right corner below the navbar using CSS

I am currently in the process of learning HTML and CSS, and I would like to practice and conduct research whenever I encounter difficulties. Recently, I have been attempting to style my landing page based on a screenshot that I took. However, I have been u ...

Display MQTT information on a Django template

I've been utilizing paho-MQTT successfully to receive messages. However, I'm facing a challenge in displaying the received data in a template. Below is an excerpt of my code: import paho.mqtt.client as mqtt import json def on_connect(client, use ...

Question about HTML Class. Explain the meaning of the hyphen (-) in a class

https://i.sstatic.net/wCbvo.png When looking at this image, is the '-' symbol serving as a connector between two ids or is the entire 'fa-facebook' considered an id? ...

Having difficulty in animating the upward movement of textbox2

I've got a form that contains 2 buttons and 2 textareas. When the form loads, I want to display only section1 (button, textarea) and the section2 button. Upon clicking the section2 button, my aim is to hide the section1 textarea, reveal the section2 t ...

Apply the CSS style to make one element identical to another, while modifying a single property

I am currently working with the following CSS: input[type="text"] { border: 2px solid rgb(173, 204, 204); height: 31px; box-shadow: 0px 0px 27px rgb(204, 204, 204) inset; transition:500ms all ease; padding:3px 3px 3px 3px; } My goal i ...

`Problem with data representation in PDF regarding page dimensions and layout`

I am currently using the datatable plugin to enable exporting to PDF, CSV, XLS, and for printing purposes. However, I am facing an issue with the PDF view. When I attempt to download the PDF file by clicking on the button, the data in the PDF does not app ...

Ways to create collapsible navigation bars in your website

As someone exploring client-side development, I may be misusing the term "collapsible" in my title. What I aim to accomplish in my web application is allowing users to collapse header bars into small chevrons and expand them back when necessary. I am on t ...

display a dual-column list using ngFor in Angular

I encountered a situation where I needed to display data from an object response in 2 columns. The catch is that the number of items in the data can vary, with odd and even numbers. To illustrate, let's assume I have 5 data items to display using 2 co ...

Display a navigation link in Bootstrap 4 when the website is viewed on a mobile

I am facing an issue with displaying a nav link on a responsive page. Below is the code snippet for reference: <div class="collapse navbar-collapse w-100 order-1 order-lg-0" id="navbarNav"> <ul class="n ...

What is the rationale behind jQuery.each not using Array.forEach when it is accessible?

After delving deep into the codebase of the underscore library, I came across an interesting discovery. It seems that _.each relies on an ECMAScript 5 API called Array.forEach whenever it is available: var each = _.each = _.forEach = function(obj, iterato ...

I require assistance in integrating this code into a jQuery function within a .js file

In a previous discussion, Irina mentioned, "I have created a responsive fixed top menu that opens when the Menu icon is clicked. However, I would like it to hide after clicking on one of the menu items to prevent it from covering part of the sliding sectio ...

Is there a way for me to generate a preview thumbnail for my video?

Looking to add a preview effect to video thumbnails when users hover over them, displaying a series of frames from the video. Are there any jQuery plugins or tutorials available for creating this effect? ...