// Repaints the progress bar's filled-in amount based on the % of time elapsed for current video.
progressBar.change(function () {
var currentTime = $(this).val();
var totalTime = parseInt($(this).prop('max'), 10);
// Don't divide by 0.
var fill = totalTime !== 0 ? currentTime / totalTime : 0;
// EDIT: Added this check, testing with it now.
if (fill < 0 || fill > 1) throw "Wow this really should not have been " + fill;
var backgroundImage = '-webkit-gradient(linear,left top, right top, from(#ccc), color-stop(' + fill + ',#ccc), color-stop(' + fill + ',rgba(0,0,0,0)), to(rgba(0,0,0,0)))';
$(this).css('background-image', backgroundImage);
});
I'm filling a progress bar over time using the above javascript to modify its background-image with a gradient.
Extremely intermittently -- the background image just entirely stops rendering. I've placed logging throughout this code and everything seems to be firing properly. I'm not dividing by 0, nor is my fill 0, but the background image stops showing up.
If I reload the dom element -- it starts to work again! So, I'm wondering if I'm just doing something really wrong here. Maybe I can't set background-image like so continuously for hours?
EDIT: I'm going to try and get a short video clip going with some logging to highlight the issue. It might take me a bit to reproduce.
I put a breakpoint into the code and observed the value of fill to be a value greater than 0 and less than 1. In this instance its value was 0.6925
Putting a breakpoint into the code, breaking on the point and then allowing execution to continue causes the progress bar's fill to re-appear!
EDIT2: Here's a video of it happening: http://screencast.com/t/DvzBr06f