I'm trying to make loader, similar to that red line on top of the page of youtube.
I have a div, that represents line.
<div class="line" style="border-bottom: 3px solid red"><div>
In the beginning of loading process, I make the width of that div 10% of normal:
$('.line').css('width', 10%);
Then, on each loading step, I want to add width by 10%.
function loadStep () {
var width = $('.loader').css('width'); //get the current width, suppose it 10%
var nextWidth = width + 10%; //calc next width
$('.line').animate({width: "20%"}, 500); //I want to animate it to next width
}
Problem is - when I get var width, it is in Pixels, not Percents. So I'm not able to add required 10%.
How do I get actual width of element in percents? I've tried this:
var width = $('.line').attr('style').split(' :')[1]
It does work when first function run is completed and we have style attribe, althoght it is sill a messy method, parsing style attr.
Any suggestions?