Can I Update A Js Variable's Property Dynamically From Another Variable?
I'm trying to update a property of a jS variable using the scroll velocity which I'm storing in another variable. This is my code thus far (scroll to the second code box as the fir
Solution 1:
You can take any object field reference using dot like
grainOptions.grainOpacity
Then you can redefine field value as using let
variables.
Update your scrollGlitch function:
function scrollGlitch(event) {
var y = event.deltaY;
var scaleY = y;
var divider = 100;
var sum = scaleY / divider;
grainOptions.grainOpacity = sum;
}
Note. In JS you can take Object fields' value with 2 ways:
- With saving reference on field to update it's own value. Ex:
grainOptions.grainOpacity.
- Only for take value. Ex:
grainOptions['grainOpacity']
Post a Comment for "Can I Update A Js Variable's Property Dynamically From Another Variable?"