0

I have the following math problem inside JavaScript.

The problem: As x decreases, I need y to decrease proportionately to x as y approaches 0%.

And so when x = 0%, y = 0%.

<script type="text/javascript">
    x = 0.50;
    y = 0.30;
    if (x < 0.50){
        // set y here somehow to gradually increase
    }
</script>
4

1 回答 1

1

变化y将是变化的 0.6 倍x(假设您希望y从 0.3 线性减少到 0.0,因为x从 0.5 减少到 0.0):

if (x < 0.50)
{
    y = 0.3 - 0.6*x;
}
于 2013-10-03T20:21:10.873 回答