I was not easy to understand what you try to achieve, but if you just want to position the current price marker relative to the scaled target marker, I would do the following.
You position the current price marker relative to the target price marker which is scaled to the percentiles 25%, 50% and 75%.
0.05 is 5% of 1.0 not 0.5%.
Use the following variables:
C := Current Price
T := Target Price
TH := 1.05 * Target Price
CP := the value that corresponds to the position of the C marker.
(to be computed)
TP := the value that corresponds to the position of the T marker.
(50% # 0.5)
THP := the value that corresponds to the position of the TH marker.
(75% # 0.75)
s := scaling factor (to be computed, just theroetically)
TH - T = s * (THP - TP)
(TH - T)
s = ----------
(THP - TP)
(1.05*T - T) T
s = ------------- = ---
0.25 5
You positioned the target price (T) to 50%.
Then you can compute the position (CP) of the current price (C) like:
C - T
C - T = s * (CP - TP) -> CP = -------- + TP
s
5 * ( C - T ) C
CP = --------------- + 0.5 = (--- - 1) * 5 + 0.5
T T
CP% = CP * 100;
You have to change the line:
$('.current-price').css({
'bottom' : ((current / target - 1) * 5 + 0.5 ) * 100 + '%'
} );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…