Edit 2:
The following is the code i was looking for
var curr_val_calc = curr_val * 0.03125 * 32;
var perc_of_max = (curr_val_calc / max_value * 100).toFixed(3)
Edit: The circle is a health bar indicator for a game, each time the game does a push the current health value updates.
Consider I have a circle with a percentage range of 0% (full) to -17% (empty). I would like my circle to change in 0.53125%
increments which would be 32 different times in 17%.
I will have a variable for max value and current value. I want to write a function that will determine the percentage of the circle based on the current value.
I need to figure out how to calculate the 50_PERCENT_OF_MAX_VALUE, 25_PERCENT_OF_MAX_VALUE, ...
and so on based on the following example. And have 32 different options for background-position-y: 0%;
.
Something like:
// These variables are dynamic
var max_value = "700";
var curr_value = "659";
// if ( 659 >= 350 )
if ( curr_value >= 50_PERCENT_OF_MAX_VALUE) {
$('#orb').css('background-position-y', '-8.5%');
}
// if ( 659 >= 175 )
if ( curr_value >= 25_PERCENT_OF_MAX_VALUE) {
$('#orb').css('background-position-y', '-4.25%');
}
if ( curr_value >= 3.125_PERCENT_OF_MAX_VALUE) {
$('#orb').css('background-position-y', '-0.53125%');
}
And so on....
Below is the code for my circle:
#orb {
width: 70px;
height: 70px;
border-radius: 100px;
border: 1px solid;
cursor: pointer;
overflow: hidden;
background: transparent url(https://ak8.picdn.net/shutterstock/videos/9273158/thumb/1.jpg) 50% 50% no-repeat;
color: #000;
font-size: 12px;
text-align: center;
}
<div id="orb" style="background-position-y: 0%;"></div>