Continuous Advancement Meter

I have implemented a progress bar, but I am encountering some issues with it.

The progress bar is supposed to complete in 5 seconds. However, the value updates every second rather than continuously, causing it to pause intermittently.

DEMO

HTML

<dx-progress-bar
#progressBar
[showStatus]="false"
id="progress-bar-status"
[rtlEnabled]="true"
[class.complete]="progressBar.value == maxValue"
[min]="0"
[max]="maxValue"
[value]="maxValue - seconds"
>
</dx-progress-bar>

.Ts

 seconds = 5;
  maxValue = 5;
  intervalId: number;

  onButtonClick() {
    this.seconds = 5;
    this.intervalId = window.setInterval(() => this.timer(), 1000);
  }

  timer() {
    this.seconds--;
    if (this.seconds == 0) {
      clearInterval(this.intervalId);
    }
  }

intended result

Example

Answer №2

To ensure that the timer function runs smoothly, it is recommended to execute it every animation frame for optimal performance:

   let seconds = 5;
   let maxValue = 5;
   let lastFrame = undefined;
   let intervalId: number;
    
   onButtonClick() {
     this.seconds = 5;
     this.intervalId = window.requestAnimationFrame(this.timer);
   }
    
   timer(time) {
     if (this.lastFrame == undefined) {
       this.lastFrame = time;
     }
     this.seconds -= (time - this.lastFrame);
     this.lastFrame = time;
     if (this.seconds > 0) {
       this.intervalId = window.requestAnimationFrame(this.timer);
     }
   }

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

Pressing the tab key makes all placeholders vanish

case 'input': echo '<div class="col-md-3"> <div class="placeholder"> <img src="images/person.png" /> &l ...

What is the best way to trigger an ajax request when a user selects a tab?

How can I trigger an ajax call when a tab is clicked by the user? What is the best way to handle the HTML response and display it within the tab? How do I bind JavaScript events to the dynamically loaded HTML content? I am familiar with using jQueryUI tab ...

The object is given a value in the form of a string, even though it is a strongly-typed variable

I'm encountering something unusual in my code. In the following example, there is a (change) event that captures the current value selected by the user from a dropdown menu. <div style="padding-right: 0; width: 100%;"> <label st ...

Requesting with the '&' symbol (amp)

Attempting to send a jQuery AJAX request with the "&" symbol in the URL: var fileName = 'test&.pdf'; var resultUrl = url + encodeURIComponent(fileName); The resulting URL is /Download/cbe1952c-1b16-40bc-9f93-7a801e0e68b8/true/test%2526.pdf. ...

Forward to a task with a unique identifier obtained through asynchronous JavaScript calls

I am currently working on an application that utilizes AJAX with FullCalendar functionality. My goal is to enable users to click on a specific item on the calendar, prompting a dialog box with a "View Details" button. Clicking on this button should redire ...

Is there a way to detect the completion of the fadeout animation before calling a function?

I am trying to create a toast message using jQuery. When the "show" class is appended to the div, I want the toast message to fade in and then fade out after a few seconds. Once the fade-out animation is complete, I need to remove the "show" class. This ...

Acquire the HTML code, make substitutions, and save it as a string variable without altering the DOM element

I have a DOM element that looks like this: <div class="list-item"> <div class="name"></div> <div class="id" data-id=""></div> <a href="">Link</a> </div> ...

Testing the output of a directive in a component unit test by simulation

One of the features I implemented in my Angular 5 component is utilizing the typeahead directive from ngx-bootstrap. Here's a snippet of how it's integrated: <input [(ngModel)]="inputted" [typeahead]="days" (typeaheadOnSelect)="select($ ...

My authentication process involves utilizing auth0 for verifying users, coupled with an API designed for creating, reading, updating, and deleting posts which include fields for titles, images, and descriptions. What steps should be

I am currently in the process of developing a react application and have implemented auth0 for user authentication. Prior to integrating auth0, I was sending CRUD requests to my API to create posts without any user authentication in place. Now that I have ...

What causes JavaScript image to stop loading while displaying a prompt dialog?

I have nearly finished my project. I will include a codepen link at the end of the post for debugging purposes. What Should Happen? The img element has an id property of dragon, and the image specified in the src attribute should be pre-loaded as the defa ...

What is the method for triggering the output of a function's value with specified parameters by clicking in an HTML

I am struggling to display a random number output below a button when it is clicked using a function. <!DOCTYPE html> <html> <body> <form> <input type="button" value="Click me" onclick="genRand()"> </form> <scri ...

When working with Sequelize querying, the response is showing an error indicating a column that does

I am currently developing a small REST API in express.js using the ORM sequelize. Currently facing the following issue: I want to retrieve all customers along with their photos. I have two tables, Customer and CustomerPhoto, with a 1:1 relationship (meani ...

Outdated JavaScript Alert

Is it possible to use JavaScript to create an alert message in my input field when a past date is selected? I would like the warning to say "past date, please enter a valid date." <html lang="en"> <head> <meta charset="U ...

Group objects with the same id in an array into separate arrays

Suppose I have an array of objects called 'myArray' that is populated as follows: var myArray = []; The objects in 'myArray' are structured like this: var myObject = { id: 1, name: 'example' }; If 'myArray' co ...

Encountered a mysterious "Karma - Unknown provider" issue relating to the menuFactoryProvider and menuFactory

Encountering issues while testing my controller with Karma, I am faced with a series of errors all originating from: Karma - Error: [$injector:unpr] Unknown provider: menuFactoryProvider <- menuFactory It appears that menuFactory (now a service) i ...

On mobile devices, the code "location.assign(url)" may occasionally redirect to an incorrect URL, despite functioning correctly in the majority of instances

After setting up a page with a timeout that should automatically redirect to a specific URL after 60 minutes, I encountered an issue where the redirection sometimes leads to a loss of parameters in the URL. The JavaScript code added for this purpose is set ...

Tips on incorporating JavaScript files into Angular applications

Struggling to incorporate a JavaScript function into Angular, I have installed the plugin "npm I global payments-3ds". I copied the JavaScript files from node_modules and attempted to call them in my component. Below is an example: import { ...

JS and MUI are combining forces to create a dynamic background change on the page when selecting items from a dropdown menu

I encountered an unusual issue on my website that appears to be related to the UI library I am using. Whenever I click on a select element, the background undergoes a slight change in width, causing the background image to flicker. Initially, I assumed thi ...

Updating Information Using JQuery

In my view, there is a partial view that displays details of open IT Tickets. Clicking on an open ticket loads the partial view with ticket details and comments using JQuery/Ajax. However, I'm facing an issue where if a new comment is added to a tick ...

Invoking a jQuery request to a C# API endpoint

I have recently embarked on a project utilizing ASP.NET MVC and JavaScript/jQuery. I am facing an issue where my API call to the controller using $.ajax function always returns a 404 error. Despite researching and trying various solutions, I continue to en ...