I was searching the internet for a solution to a problem I'm facing, and came across this great topic! So what I'm looking for is a progress bar to visually display the remaining time of a quiz. The quiz has a preset duration value (ie. 3 mins), which I can easily pass to JS from PHP when calling the JS. Additionally, in order to deal with sneaky persons who might try to refresh the page, attempting to gain some extra time, at the first time the page loads, I store the timestamp of that moment.
So if someone attempts to do a page refresh, the script will load the stored starting time, subtract it from [now], and thus calculate the remaining amount of seconds. Ie. if the quiz initially started at 16:50:15 (a unix timestamp is stored actually), and the duration of the quiz is 180s (3 mins), normally the timer will stop at 16:53:15. Now, if a sneaky player refreshes the page at 16:51:15, the system will know that only 120s of time are left, and will start from there.
But with the timer of the link above, if I set the duration to 120s, it'll start with a full progress bar, only this time it'll reduce faster... Ideally I'd like it to start at two thirds (2 mins remaining) of the bar, and keep the previous reducing ratio...
The problem is I can't think of a way to achieve that. Could someone help me figure that out?
What I'm thinking is to calculate an additional @keyframe at [xx]%, where [xx] is the remaining time / total duration, but then I don't know if/how I can set the animation to start from that @keyframe, instead of @100%... Am I on the correct path?
Update: Obviously I rushed into opening this topic... There is a CSS rule to achieve what I need... All that was needed is to add a negative animation-delay in seconds, like animation-delay: -60s and CSS takes care of this delay in terms of picking the correct color from the gradient between the two keyframes (0% - 100%), and also starts from that point... Absolutely brilliant... Take a look at this fiddle!!!
Also, while I changed the gradient (of start and end) colors to the ones that suit my needs better, I'd also like to make the whole progress bar have that pattern of diagonal "moving" lines (like this) while reducing. I tried with a gif and adding some alpha to the color of the progress bar, but it didn't work. Or I may have done it wrong. Could someone help me figure that out as well?