I'm trying to work out a percentage from 0 - 100 from a part of HTML video
When the HTML video hits 5.89 secs I would like the animation to complete on 10.05 im having troubles doing this so far i have worked out the percentage of the time below
So there is 4.16 inbetween the times stated and it works out to be 1% is 0.041600000000000005
I have added the current time into the function becuase i need to work out what percent the video is on while its playing
var animationOneStart = 5.89;
var animationOneEnd = 10.05;
function perentageTime(animationStart,animationEnd,currentTime){
var timeInbetween = animationEnd - animationStart;
a = 1/100;
b = a*timeInbetween;
return b;
}
I'm having troubles working out the percentage while it playing would anyone be able to help me please?
Thanks
The formula for percentage is (currentValue / maxValue) * 100
so, in your case will be (currentTime / timeInbetween) * 100
Here is an example:
var animationOneStart = 5.89;
var animationOneEnd = 10.05;
function perentageTime(animationStart,animationEnd,currentTime){
var maxValue = animationEnd - animationStart;
var ret = (currentTime / maxValue) * 100;
return ret.toFixed(2);
}
var percentage = perentageTime(animationOneStart, animationOneEnd, 1);
console.log(percentage);
This will work only if currentTime
starts from 0
, if it starts from animationOneStart
, you'll need to use ((currentTime - animationOneStart) / maxValue) * 100
</div>