I am using the following translateRange
function to calculate the range between multiple factors like this:
function translateRange(
input,
inputMin,
inputMax,
outputMin,
outputMax
) {
let inputMinA = Math.min(inputMin, input);
let inputMaxA = Math.max(inputMax, input);
return (
outputMin +
((outputMax - outputMin) * (input - inputMinA)) /
(inputMaxA - inputMinA)
);
};
let opacity = translateRange(
scrollY, //input
0, //animation start
100, //animation end
0, // from 0
1 // to
);
This works best, but i want to pass multiple values to the function. For e.g. i want to pass x
and y
values for transform
animations at the same time. How can i change the function to get this working? I would like to end with something like this:
let translate3d = translateRange(
scrollY,
0,
100,
[-10, -5], // x values (start and end)
[-4, 1] // y values (start and end)
);
When you scroll, i want to get the calculated values like this:
-10, -4 // x and y start values