Track the reading progress of each article on a single page with individual progress bars

Is it possible to customize the progress bar for each individual article on a single page? I attempted to use code from (Reading Position Indicator based on DIV instead of the whole page), but it only seems to work with the first div.


$(document).on('ready', function() {
  var winHeight = $(window).height(),
    docHeight = $(document).height(),
    progressBar = $('progress'),
    max, value;

  /* Set the max scrollable area */
  max = docHeight - winHeight;
  progressBar.attr('max', max);

  $(document).on('scroll', function() {
    value = $(window).scrollTop();
    progressBar.attr('value', value);
  });
});

progress {
  /* Positioning */
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  width: 100%;
  height: 3px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  /* Get rid of the default border in Firefox/Opera. */
  border: none;
  /* Progress bar container for Firefox/IE10+ */
  background-color: transparent;
  /* Progress bar value for IE10+ */
  color: #E60000;
}

progress::-webkit-progress-bar {
  background-color: transparent;
}

progress::-webkit-progress-value {
  background-color: #E60000;
}

progress::-moz-progress-bar {
  background-color: #E60000;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<progress value="0"></progress>

Answer №1

If I understand correctly, you are looking to modify several progress bars simultaneously. Here is a snippet of code that might assist you:

$('progress').each(function(index,elem) {
    elem.attr('value', newValue);
});

Remember to apply the same method for both 'min' and 'max' values as well.

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

The HTML5 Canvas Misalignment Issue

I currently have some HTML code that includes a canvas, span, and a button: <canvas id='myCanvas'></canvas> <span id='coords'></span> <button class='clear'>clear</button> Accompanying this ...

When I try to access an element by its ID using JavaScript, the value

Just so you know, this is a unique question - I couldn't find an answer in similar queries. I'm attempting to capture and display this element: <p id="one">Test</p> using JavaScript to log it to the console: var one = document.get ...

Adjust background color on click using JavaScript

Could someone provide me with the JavaScript code to change the background color of a page from blue to green when a button is clicked? I have seen this feature on many websites but haven't been able to write the code myself. I am specifically lo ...

Setting up the FullCalendar to display events based on their respective time slots

I've incorporated FullCalendar into my project, but I'm encountering an issue when adding events with different start and end dates. start: "04/18/2018 22:05:00", end : "04/19/2018 02:05:00" Even though the time difference is only 4 hours, the ...

Adjust the width of the table after refreshing it for 10 seconds when resizing the column?

I am facing an issue with a page that refreshes every 10 seconds and has a resizable column feature. However, after the page refresh, the table header (th) reverts back to its original position. The main question is how to obtain the width of a specific ...

JavaScript: converting to string

Why does Object.prototype.toString === toString? When I include the following code in the global scope: var toStringValue = toString.call("foobaz"); I assume that toStringValue would be the value of window.toString since window is the default scope, corre ...

The issue at hand is that one of the JavaScript buttons is functioning properly, while the other is not playing the video as intended. What steps can

I've been working on a script for my school project website that should make buttons play videos, but I'm running into an issue where it only works for the first button (btn). Programming isn't my strong suit, and I put this together based o ...

Replace the content of one div with different code using separate divs

When I click on my favorite button, I want the content of a div with the id "content" to change to display my favorite code with other divs. I'm not sure if I should use jQuery Ajax or something else. Here is my code, but I'm not sure how to ach ...

What could be the source of this margin or spacing?

Within this test, I have noticed that there are 2 inline flex containers. Specifically, I am referring to the test scenario that states Next The flex containers are laid out inline. Despite the fact that there is some space between the containers, upon in ...

What is the process for undoing changes on a Kendo Grid?

There's an issue in my kendo grid where clicking on a cell puts it into edit mode, but I need to be able to cancel the edit based on certain conditions. I attempted using jQuery code to simulate pressing the escape key, but unfortunately that did not ...

Display numbers in Vue with the thousand separator

I am currently using a division calculator that is functioning properly, but I am not satisfied with the calculation results. The issue becomes more clear when you refer to the screenshots below. What I aim to achieve is to remove unnecessary zeros, add co ...

Angular17+ introduces a new feature called the Dynamic Tag Class, providing

Why isn't my navigation bar updating when the page changes? Here is my app.component.html code: <html> <app-navbar></app-navbar> <router-outlet></router-outlet> </html> This is where my navbar.component.html s ...

If the initial tab is not visible, activate the first tab that is currently visible

I need some assistance with jQuery UI Tabs. My menu includes 6 tabs, with the first tab always being "active." However, in some scenarios, one or more tabs may be hidden using "display: none;". Is there a method to identify the first visible tab and set it ...

What could be causing my PHP code to not execute properly alongside the HTML?

I am currently sharpening my skills in PHP by working on a simple web form project. To put it simply, I need to develop a basic web form that accepts a two-dimensional array of European cities along with the distance in kilometers between each pair of citi ...

MVC Controller and JavaScript Ajax Call necessitate authentication for communication

In my ASP.NET MVC application, I am utilizing AJAX calls from the Client Page using AngularJS service to perform CRUD operations through Controller Action methods. While I have implemented ASP.NET form authentication for my MVC Pages, I am now looking to ...

Is there a way to locate a parent class starting from a child class, and subsequently track down another child class from the parent?

I am facing a challenge with multiple tags structured like this: <div class="A"> <div class="B1">...</div> <div class="C1">Hello World!</div> <div class="C2">World Hell ...

Creating Global Variables in Node/Express Following a Post/Get Request

How can I dynamically pass the payment ID received after a POST request to a subsequent GET request in Node/Express for a payment system? Below is an example code snippet from my project: let paymentId; app.post("/api/payments", (req, res) => ...

Dealing with an unspecified parameter can be tricky - here's how you

Currently, I am in the process of developing an angular application. In this project, there is a specific scenario that needs to be handled where a parameter is undefined. Here's a snippet of my code: myImage() { console.log('test') ...

Experimenting with Angular using a template that includes a mat-toolbar

Currently, I am in the process of writing tests for my Angular application. Here is a snippet of the template used in my AppComponent: <mat-toolbar color="primary"> <span>CRUD Exercise</span> <span class="example-spa ...

developing versatile paths with Node.js

app.js // Including Routes require("./routes")(app); router folder index.js module.exports = function (app) { app.use("/", require("./all_routes")); } all_routes.js var express = require("express"); var route ...