I am trying to make a YouTube-like progress bar. The bar should load at the page startup. I have tried this so far. Here is the code of my script
$({property: 0}).animate({property: 105}, {
duration: 4000,
step: function() {
var _percent = Math.round(this.property);
$('#progress').css('width', _percent+"%");
if(_percent == 105) {
$("#progress").addClass("done");
}
},
complete: function() {
alert('complete');
}
});
I am also including the jsFiddle of the same, http://jsfiddle.net/ajaSB/3/.
In this jsfiddle, the progress bar appears, but when I use the same code in my IDE and run the file no progress bar appears. What am I doing wrong? Or if there is another way to get the bar?
An image loading demo by Nprogress may help.
Code from TalkersCode.com and tutorial here http://talkerscode.com/webtricks/display-progress-bar-while-page-loads-using-jquery.php
You can get the plugin for the progress bar
I have published it on GitHub
https://github.com/shashibeit/progressbar
you will need to include in your project and call the below functions
Progress.start();
Progress.go(20);
Progress.go(30);
Progress.go(80);
Progress.go(100);
Progress.complete();
NProgress.js is a very cool and simple library. The Git repository is here. It has an MIT License.
If you want a 'youtube-like' loader for your AJAX application that actually represents legitimate page loading progress, consider the following solution (based on Nathan Srivi's answer):
In your
.ajax()
method:Then, in your css; use this:
And now you should have a loader that works for each AJAX operation...and really works to represent the true percentage of how much of the response has been received, instead of just playing a fancy animation when you first load the main page.
To make it operational on the initial page load (i.e. its not actually displaying legitimate progress), use the method that Nathan Srivi mentions in a
document.ready
function above and beyond what I already mentioned:Lastly,
You will need to ensure that 'Content-Length' headers are being sent to the browser in order for a loader of this design to work correctly...otherwise the
event.lengthComputable
member resolves to false...and no progress bar will load.HTH, feel free to edit inconsistencies.
Demo : Fiddle
Try the following code. You must run this file into your localhost (local server).
Or:
Just upload this file to your server, and then you execute the file. Definitely it works.