An easy guide to animating multiple sections of progress bars individually in Bootstrap

My Bootstrap code successfully animates a section of progress bars when the user views it. However, it currently animates all progress bars on the page rather than just those in the viewed section. This means that when the user moves to another section, the bars are already animated and no further animation is visible.

How can I modify the code below to independently animate different sections as they come into view?

CSS

#skills {
  padding: 60px 0;
}

#skills .progress {
  height: 35px;
  margin-bottom: 10px;
}

#skills .progress .skill {
  font-family: "Open Sans", sans-serif;
  line-height: 35px;
  padding: 0;
  margin: 0 0 0 20px;
  text-transform: uppercase;
}

#skills .progress .skill .val {
  float: right;
  font-style: normal;
  margin: 0 20px 0 0;
}

#skills .progress-bar {
  width: 1px;
  text-align: left;
  transition: .9s;
}

JS

// Skills section
$('#skills').waypoint(function() {
  $('.progress .progress-bar').each(function() {
    $(this).css("width", $(this).attr("aria-valuenow") + '%');
  });
}, { offset: '80%'} );

HTML


<!-- First section of progress bars somewhere on the page -->
<section id="skills">
  <div class="skills-content">
    <div class="progress">
      <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria- 
   valuemax="100"></div>
        <span class="skill">Skillset 1 - Skill 1 <i class="val"></i></span>
      </div>
    </div>
    <div class="progress">
      <div class="progress-bar" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria- 
   valuemax="100"></div>
        <span class="skill">Skillset 1 - Skill 2 <i class="val"></i></span>
    </div>
  </div>
</section>

<!-- Another section of progress bars further down the page -->
<section id="skills">
  <div class="skills-content">
    <div class="progress">
      <div class="progress-bar" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria- 
   valuemax="100"></div>
        <span class="skill">Skillset N - Skill 1 <i class="val"></i></span>
      </div>
    </div>
    <div class="progress">
      <div class="progress-bar" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria- 
   valuemax="100"></div>
        <span class="skill">Skillset N - Skill 2 <i class="val"></i></span>
      </div>
    </div>
    <div class="progress">
      <div class="progress-bar" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria- 
   valuemax="100"></div>
        <span class="skill">Skillset N - Skill 3 <i class="val"></i></span>
    </div>
  </div>
</section>

Answer №1

i just noticed you're not properly closing your section elements and other tags

<section class="skills">
    <div class="skills-content">
        <div class="progress">
            <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria- valuemax="100">
            </div>
            <span class="skill">Skillset 1 - Skill 1 <i class="val"></i></span>
        </div>
        <div class="progress">
            <div class="progress-bar" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria- valuemax="100">
            </div>
            <span class="skill">Skillset 1 - Skill 2 <i class="val"></i></span>
        </div>
    </div>
</section>

<!-- Another section of progress bars further down the page -->
<section class="skills">
    <div class="skills-content">
        <div class="progress">
            <div class="progress-bar" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria- valuemax="100">
            </div>
            <span class="skill">Skillset N - Skill 1 <i class="val"></i></span>
        </div>
        <div class="progress">
            <div class="progress-bar" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria- valuemax="100">
            </div>
            <span class="skill">Skillset N - Skill 2 <i class="val"></i></span>
        </div>
        <div class="progress">
            <div class="progress-bar" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria- valuemax="100">
            </div>
            <span class="skill">Skillset N - Skill 3 <i class="val"></i></span>
        </div>
    </div>
</section>

when calling your waypoint function, make sure to target only child progress elements instead of all progress elements

$('#skills').waypoint(function() {
  $('.progress .progress-bar').each(function() { // <- ensure you are targeting only child progress elements
    $(this).css("width", $(this).attr("aria-valuenow") + '%');
  });
}, { offset: '80%'} );

update it to

$('.skills').waypoint(function () {
   var el = this.element;
   var children = $(el).find(".progress-bar");
   $(children).each(function () { // <- make sure to target only children elements
        $(this).css("width", $(this).attr("aria-valuenow") + '%');
   });
}, { offset: '80%' });

also, ensure that other skills sections are not visible to users when the page loads (not in the viewport)

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

Answer №2

To ensure smooth functionality, consider utilizing distinct classes in your HTML markup. Then, in your JavaScript code, initialize these different classes individually as required.


    <div class="progress">
      <div class="progress-bar progress-bar-1" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria- 
   valuemax="100"></div>
        <span class="skill">Skillset N - Skill 3 <i class="val"></i></span>
      </div>
    </div>

$('#skills').waypoint(function() {
  $('.progress-bar.progress-bar-1').each(function() {
    $(this).css("width", $(this).attr("aria-valuenow") + '%');
  });
}, { offset: '80%'} );

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

- bullet point: tabulated

I need to create an unordered list with URLs included and indented, while keeping all lines justified to the left. * line one text text ted more text text text * line two text ted more text text text * line three text ted more text text text ...

Executing JavaScript code does not execute CSS code

Having some trouble with my Javascript and CSS. The script is functioning well, but when I use the filtering function, the CSS stops working and only the filtered results are displayed on the HTML page. Looking for advice on how to fix the Javascript. & ...

Tips for transferring <form> information to an object array within a React application

I am currently working on a basic component that takes an input message, displays it in a list below the input field when submitted. However, I am facing an issue where clicking the submit button only results in a blank bullet point appearing below. impo ...

The second attempt at an AJAX call is unsuccessful

I am currently developing a form that displays database results based on two entries: Automarke (brand) and Modell (model). You can view the entries here. The Modell dropdown dynamically changes based on the selected Automarke. Here is the code snippet I ...

Setting up the JSON reply

When creating a schema using Joi and expecting a JSON response that matches the schema upon POSTing, an issue arises. The dilemma is having to include a parent element (in this case "data:") in the JSON response, although ideally the schema's attribut ...

Tips to prevent the webpage from scrolling to the top when clicking on an anchor with an ID

I have developed a CSS/HTML carousel that consists of 4 slides. The goal is to display the selected slide when clicking on the bottom button (a href). However, I am facing an issue where every time I click on a link, the selected slide appears as intended ...

Deactivate the image button when no image has been chosen from the input field

Is it possible to have the image button disabled when no image is selected in the input field? The button should be inactive if an image is not chosen. import { useState } from "react"; const CommentForm = ({ handleSubmit, submitLabel }) => ...

Highlighting with pretty JSON formatting

Is there a way to format JSON on a website and emphasize certain text or lines within it? Ideally, I'm looking for an IFRAME service that I can link to a URL where the JSON is downloaded and displayed as HTML. I want to be able to specify a search st ...

"findByIdAndUpdate continues to work successfully even when the request body includes parameters that are not defined in

Referenced from This particular tutorial on MERN stack development... In my mongoose schema, I have defined 4 fields: const mongoose = require('mongoose'); const Schema = mongoose.Schema; let Todo = new Schema({ name: { type: String ...

Creating a dynamic dropdown menu that changes based on the selection from another dropdown menu

I'm working on a project that requires users to make specific selections in dropdown menus that are interconnected. Does anyone know how to set up a form so that the options in dropdown menu #2 change based on what the user selects in dropdown menu #1 ...

Tips for passing an additional parameter to a function within the map method in JavaScript

Is there a way to pass an additional parameter to the aggregationFunction in JavaScript when using dataArray.map(self.aggregationFunction)? I attempted using .bind(extra parameter) but it didn't yield the desired result. Any advice would be appreciate ...

3 Methods for Implementing a Floating Header, Main Content, and Sidebar with Responsive Design

I am following a mobile-first approach with 3 containers that need to be displayed in 3 different layouts as shown in the image below: https://i.sstatic.net/UjKNH.png The closest CSS implementation I have achieved so far is this: HTML: <header>.. ...

The error has not been handled properly and is being thrown at line 174 in the events.js file

I encountered an issue while trying to request data from an API, resulting in a crash on any Windows server. Can someone lend a hand with this problem? Here is a snippet of my code: app.get("/js/2806/api/products/getAllDrugs", (req, res) => { co ...

nextJS does not recognize the term 'Window'

I'm encountering the error "window is not defined" in my NextJS project. The variable isMobile determines whether the window size is less than 767.98 to handle the hamburger menu functionality. This code worked in ReactJS but seems to be causing issue ...

Executing a series of API calls using Rxjs in Angular that result in a null response

I encountered a situation where I needed to make sequential API calls using RxJs in Angular. However, despite successfully implementing the calls, I am struggling with a null error. In this scenario, the second API call depends on receiving an id from the ...

Unlock the full potential of integrating external APIs with Next.js

As a newcomer to NextJs, I am facing the task of making calls to an external Python API from my frontend. Upon discovering NextJs's integrated API feature through creating folders in the app directory, namely api/resource/route, I am wondering what th ...

Utilize CSS Animation to bring overlapped images to life

Trying to replicate the animation featured on the CISO website header. I have created a JSFiddle demo showcasing my attempt, but it seems like something is not quite right. img { transition: all .3s ease; overflow: hidden ...

Mastering the map() function in Vue.js 2

As I start learning vue.js, I am facing some challenges. I need to implement a dictionary analog in JavaScript, known as a map. However, I'm unsure of where to define it. The map should be utilized in both the checkDevices() method and within the HTML ...

Error: Unable to assign value 'auto' to property of null object

Whenever I attempt to update my MongoDB using AngularJS on the front end and Node.js on the backend, I encounter a `TypeError: Cannot set property 'auto' of null error. Here is the code snippet that resulted in this issue: AngularJS Code: scope ...

HTML/Javascript/CSS Templates: Keeping Tabs on Progress

I'm looking for templates that use notepad as an editor for html/javascript/css. I want to find a template that displays text or pictures upon clicking, like the example below: Sorry if this is a silly question, it's been 8 years since I last di ...