Animating a reverse progress bar in jquery with unique effects

I've been struggling to fix a progress bar issue. I downloaded one, but it's showing reverse animation. Despite my attempts at troubleshooting, nothing seems to work. Any suggestions on how to resolve this?

Here's my HTML:

<!doctype html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script type="text/javascript" src="progressbar.js"></script>

<link rel="stylesheet" type="text/css" href="progressbar.css">
<link rel="stylesheet" type="text/css" href="skins/default/progressbar.css">

</head>
<body>


<div id="progressBar" class="default"><div></div></div>


<script>
    progressBar(40, $('#progressBar'));
</script>

</body>
</html>

This is the CSS:

.default {
background: #292929;
border: 1px solid #111; 
border-radius: 5px; 
overflow: hidden;
box-shadow: 0 0 5px #333;               
}
.default div {
background-color: #1a82f7;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0099FF), to(#1a82f7)); 
background: -webkit-linear-gradient(top, #0099FF, #1a82f7); 
background: -moz-linear-gradient(top, #0099FF, #1a82f7); 
background: -ms-linear-gradient(top, #0099FF, #1a82f7); 
background: -o-linear-gradient(top, #0099FF, #1a82f7);
}

Finally, here's the JavaScript file:

function progressBar(percent, $element) {
var progressBarWidth = percent * $element.width() / 100;
$element.find('div').animate({ width: progressBarWidth }, 500).html(percent + "%&nbsp;");
}

Modified CSS for reference:

.default {
background: #292929;
border: 1px solid #111; 
border-radius: 5px; 
overflow: hidden;
box-shadow: 0 0 5px #333;               
}
.default div {
width: 0;
background-color: #1a82f7;
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0099FF), to(#1a82f7));
background: -webkit-linear-gradient(top, #0099FF, #1a82f7);
background: -moz-linear-gradient(top, #0099FF, #1a82f7);
background: -ms-linear-gradient(top, #0099FF, #1a82f7);
background: -o-linear-gradient(top, #0099FF, #1a82f7);
}

Answer №1

To ensure the width of your inner div starts at 0, it must be explicitly set to that value, otherwise it will default to 100%:

.default div {
    width: 0;    /*  <--- this is where you set it   */
    background-color: #1a82f7;
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#0099FF), to(#1a82f7));
    background: -webkit-linear-gradient(top, #0099FF, #1a82f7);
    background: -moz-linear-gradient(top, #0099FF, #1a82f7);
    background: -ms-linear-gradient(top, #0099FF, #1a82f7);
    background: -o-linear-gradient(top, #0099FF, #1a82f7);
}

http://jsfiddle.net/pjg99q7s/

You can view a slightly more elaborate example by visiting:

http://jsfiddle.net/pjg99q7s/2/

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

Sending a list of strings to a Controller in MVC 3 Razor

I am encountering an issue when passing a list of strings into a controller in MVC 3 Razor. I am using jQuery to set the values, but for some reason, the first value is always false on the server side. Here is my code: Class: public class ListFieldInf ...

Failure to integrate Google Map InfoBox asynchronously

Struggling to figure out how to incorporate an asynchronous Google Map with an InfoBox Plugin by Google on my website. Below is the code I currently have: <script type="text/javascript"> jQuery(document).ready(function() { loadScript(); ...

Tips for designing a table with a stationary first column in HTML/CSS

I am looking to design a table that can be horizontally scrolled with a dynamic number of columns. The goal is to keep the first column fixed/frozen while scrolling horizontally. I attempted to achieve this using the following CSS, which successfully keeps ...

Utilize ES6 in React to dynamically update state with setState and retrieve state with the

Recently I discovered a technique for handling multiple input events using dynamic state. If I have a state setup like this this.state = { name_1: 'john', name_2: 'james' } I can access my state values like this [1,2].forEach ...

What HTML element identifies the beginning of a particular section?

It has been suggested that Google frowns upon using identical content across multiple websites. Is there a method to mark or label a section of content with its "source"? For example, an attribute might look like this: <div original-content="http://s ...

"Upon the second click, the Ajax success function will display the returned view

When using a post request in angular's factory with ajax, everything seems to be working fine except for the success function. Upon clicking the login button, it seems like I have to click it twice to navigate to another page (logout.html). I'm n ...

AngularJS OAuth authentication Pop-up: Waiting for JSON response

I am looking to initiate an oauth request in a new window for my project. Here is how I can open the new window: var authWindow = $window.open("/auth/google/signin", ""); After the callback, my server will respond with JSON data: app.get('/auth/ ...

Executing a mock action when initializing a controller in AngularJS during testing

My AngularJS controller is structured as follows: app.controller('MyCtrl', function($scope, service) { $scope.positions = service.loadPositions(); // this invokes $http internally $scope.save = function() { ... }; // other $scope ...

Creating a JSON object from a dictionary: Step-by-step guide

I'm new to JavaScript and I have a situation where I receive a lengthy dictionary in the browser that looks like this: {"cat": "4" , "dog": "5", "fish": "9" } I'm curious about the most effective method to convert it into a JSON object structur ...

Error encountered when injecting Angular module

Currently, I am attempting to develop a sample Angular application with .Net in order to understand how to connect the two technologies. However, I have been encountering an error related to injector::modulerr that I cannot seem to resolve. Despite trying ...

Error: OpenAI's transcription API has encountered a bad request issue

const FormData = require('form-data'); const data = new FormData(); console.log('buffer: ', buffer); console.log('typeof buffer: ', typeof buffer); const filename = new Date().getTime().toString() + '.w ...

Tips on adding a submit button to an input field

Currently, I am iterating through and appending the given information. It is getting appended successfully but I am facing an issue when trying to append it as a submit type instead of text. When attempting to append like this, it does not work and result ...

Utilizing Selenium and Python to Extract Links from a Web Table

Currently, I am faced with a table that has two columns and an unknown number of rows. My task involves utilizing Selenium (with Python) to extract all the links from the second column and compile them into a list. https://i.sstatic.net/bvYez.png The obj ...

ngx-slick-carousel: a carousel that loops infinitely and adjusts responsively

I have implemented ngx-slick-carousel to showcase YouTube videos in my project. However, I am facing two main issues. Firstly, the carousel is not infinite, and when the last video is reached, there appears to be white spaces before it loops back to the fi ...

The intricacies of a many-to-many relationship and how to populate associated data within a query when using Keystone

I'm currently working on a KeystoneJS project and encountering an issue with the relationships between two models. Here are the details of the two models: User model: User.add({ name: { type: Types.Name, required: true, index: true }, email ...

CAUTION: Attempted to initialize angular multiple times...all because of jQuery...such a puzzling issue, isn

I am attempting to comprehend the situation at hand. The warning is clear, and I acknowledge that in my application, with the provided code and structure, the ng-view runs twice ('test' is logged twice in the console, indicating that angular is l ...

Employing a combination of distinct CSS selectors from various vendors simultaneously

I'm trying to style placeholder text in different browsers using vendor-prefixed selectors. When I use separate code blocks for each selector, it works fine. However, when I try to use a comma-separated list of selectors instead of repeating the CSS f ...

MongoDB failing to store model information

As I dive into practicing with APIs to hone my skills in creating models and routes, I find myself stuck on getting my initial route to successfully save data to my MongoDB database. When testing with Postman, I encounter the following error: { "message" ...

When applying a gradient on top of an image with background-image, the gradient appears larger in size compared to

Struggling with HTML <div class="outer"> <div class="bgimagegradient"></div> <img src="foo.jpg"> <div> .backgroundimage { position: absolute; right: 25px; z-index: -100; ...

Automating the process of posting a file to a form with javascript

I have a piece of client-side JavaScript that creates a jpeg file through HTML5 canvas manipulation when the user clicks an "OK" button. My goal is to automatically insert this jpeg output into the "Upload Front Side" field in a form, simulating a user up ...