Animating CSS Skill Bars as You Scroll

Is there a way to achieve a similar effect as seen here? I've tried implementing the code from this answer, but it's not entirely clear. The suggestion is to use this jQuery plugin, but I can't seem to make it work. I prefer using Foundation 4 for my project, which includes simpler-to-create progress bars. Additionally, the animation code in the second example looks cleaner compared to the messy and redundant code in the first example.

You can view my live code here. I'm specifically working on the skill bars in the about section. I want the animation of these bars to pause until the user scrolls to that section of the page.

EDIT: Any ideas on how to prevent the bars from extending beyond their containers when resizing the page (since the site should be responsive) would be greatly appreciated.

EDIT2: After some testing, I found that using overflow: hidden; on .progress fixes the issue with the bars breaking out of their containers. However, the sizes remain unchanged when the window is resized, affecting the appearance of button overlays. Suggestions on resolving this problem would be highly valued!

Answer №1

If you are familiar with the location of your skill bar and screen, utilizing javascript is all you need. (no need for plugins or complicated tools)

To easily obtain the vertical position of your screen:

 window.pageYOffset

To find the vertical position of your div:

 div.offsetTop

In this scenario, I suggest assigning an id to the div containing all the skill bars and setting up a loop (window.requestAnimationFrame https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame) to monitor if you are close to the div (such as when the difference between window offset and the div is minimal).

If affirmative, trigger the animation.

The most effective way to create the animation is through css transition. (for those needing guidance on css animations, check out this helpful video: http://www.youtube.com/watch?v=VoncDvOfUkk)

You can adjust css animations via javascript.

The concept involves setting all "meter" widths to zero initially. In javascript, execute something like:

 div.style.transition = "width 1s";
 div.style.width = someValue;

I recommend using a constant fraction of the "progress" div for the value in the div, expressed in %. This method should suffice. (if problems persist, keep in mind there's a window.requestAnimationFrame loop to recalculate values at each interval... however watch out for performance issues).

The reason jQuery was suggested is due to its ease in updating all divs for animation purposes, simply using $(this).find('.meter') and then addClass('.expand').

Hope this explanation proves beneficial.

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

Information sent by the Firefox TCP socket using the socket.send() method cannot be retrieved until the socket is closed

I am experiencing an issue while trying to send data from Firefox to a Java desktop application. My Java class functions as a server, and the Firefox script acts as a client. When I test it using another Java class called client.java, the data is successfu ...

Incorporating personalized CSS and JavaScript into Shopify

Currently, my project involves integrating vertical tabs into a Shopify page that is utilizing the 'Atlantic' theme. Since this particular theme doesn't come with vertical tabs built-in, I have incorporated external JS and CSS files known as ...

jquery combobox with overlapping autocomplete suggestions

Encountering an issue with the jquery autocomplete combobox where they overlap when positioned side by side. Referencing this link for guidance: http://jqueryui.com/autocomplete/#combobox <!doctype html> <html lang="en"> <head> <me ...

Creating a PDF file using an Ajax post request

I am currently using ajax to send a post request to a function responsible for generating a PDF document using TCPDF. In the past, I would simply make a regular post request to this function and it would generate the PDF for the user to download. However, ...

How to Extract Information from a Table Enclosed in a Div Using HTML Parsing?

I'm new to HTML parsing and scraping, looking for some guidance. I want to specify the URL of a page (http://www.epgpweb.com/guild/us/Caelestrasz/Crimson/) to grab data from. Specifically, I'm interested in extracting the table with class=listing ...

How do I make an element stay in place between two other elements?

Trying to make an element "float" between two other elements using the `position : sticky` attribute. Not achieving the desired effect and unable to determine why. The goal is for the `copy` to float between the bottom of `upper` and the top of `lower`. ...

Encountering Issues with Script functionality on secure websites

I tried running this code on my development machine and it worked perfectly fine over http. However, as soon as I switched to https, it stopped functioning. Any assistance on this matter would be highly appreciated. The code I am using is from zippopotamu ...

How can I display a clicked-on div while hiding all other divs using jQuery?

I want to create a website where a button can show and hide a specific div, but my challenge is; How can I ensure that clicking on one button hides all other divs? Here is the JavaScript code: function showHide(divId){ var theDiv = document.getEleme ...

Is there a reason why Social Bar isn't appearing at the top?

My challenge is to position the bar close to the black footer. It appears correctly in Chrome, but not in Firefox and Opera. The screenshot shows how it looks in Chrome. However, in Firefox and Opera, the social bar is positioned lower and does not align ...

Unable to Upload Image to MySQL Database

I encountered an unidentified index error when trying to upload images. I added a check to prevent the error, but the images are still not being uploaded. I have tested with legitimate images, but nothing seems to work. I've been struggling with this ...

"Transforming portfolio photos from black & white to vibrant color with the click of a filter button

I'm currently working on creating a portfolio that includes button filters to toggle between black and white images and colored images based on the category selected. While I have successfully implemented the functionality to change the images to bla ...

What is the best way to incorporate navigation options alongside a centered logo?

Looking to create a unique top header layout with the logo positioned in the center and navigation options on both sides. Below is the initial code, but unsure how to proceed further. Any suggestions on achieving this design? <div class="header"> ...

Select the drop-down option to categorize the list by date

Currently, I am in the process of integrating Vue.js into my project step by step, particularly for data binding purposes. To achieve this, I have included the Vue.js script in the footer and created a main.js file to house my Vue scripts. One of the chal ...

Converting a JSON array with two dimensions to PHP

My JSON encoded array originated from a 2D PHP string array and appears as follows: [ [ "a1", "a2", "a3", "a4" ], [ "b1", "b2", "b3", "b4" ], [ "c1", "c2", "c3", "c4" ] ] The validity of this array has been ...

Instructions on removing an HTML element from a div that has the attribute contentEditable

Here is an example of HTML code: <div id="editable" contentEditable="true"> <span contentEditable="false">Text to remove</span> </div> I want to be able to delete the entire span element (along with its text) with just one bac ...

Sending text content using AJAX

Recently, I've delved into the world of AJAX and JavaScript while working on a project in JSP. My goal is to submit text entered in a textarea using a JavaScript button. The first submit button worked fine initially, but upon posting, I ended up with ...

What is the method for retrieving data from the root component within a child template in VueJs?

How can I access this.$root from within a VueJs template? For example: <template> <v-card elevation="this.$root.$refs.foo.cardElevation"> Foo </v-card> </template> I am aware that I can create a data property and ...

Avoid using the JavaScript 'Sys.WebForms..' function if there is no ScriptManager present on the page

Currently, I am using a single JavaScript binding in the Master Page for my entire project. However, the Master Page does not include a ScriptManager. This means that some pages have Ajax components, such as UpdatePanel, while others do not. The 'Sys. ...

Swap out the default URL in components with the global constant

Could anyone offer some assistance with this task I have at hand: Let's imagine we have a global constant 'env' that I need to use to replace template URLs in components during build time. Each component has a default template URL, but for ...

Socket.io allows us to broadcast messages to all users connected to the server using the "io

I've set up a MEAN app using npm socket.io with expressjs and btford.socket-io on the client side. angular.module('myApp',['btford.socket-io']) .factory('socket',function(socketFactory){ return socketFactory() ...