If I have the object's var distance; set at 100. As it moves towards a distance of 0, I want the opacity to increase. How would I use that 100 incrementing down to be the reverse for the opacity? Is there math I could use to do this?
Would I just use a var count to count up from 0 to 1?
You can use opacity = (100 - distance) / 100.
This way when distance is 100 opacity will be 0 and when distance is 0 opacity will be 1.
In general if you want a transition so that as x moves from xa to xb y correspondingly moves from ya to yb you can use
y = ya + (x - xa) * (yb - ya) / (xb - xa)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With