For starters, --foo-bar as a property name can not work in this syntax - you'd have to put it in quotes. Not sure if you will be able to directly animate this then though - you might need to declare your variable as a custom property first, stackoverflow.com/a/64333786/1427878
Also I believe that CSS variables are only evaluated once at the start of the page build. Changing the variable later has no effect (as far I as I understand).
@Kokodoko I sincerely hope thats not the case because that would break quite a lot. It is only evaluated once at the start of an animation in my experience (so changing it does not really affect the animation if its running) but otherwise they should definitely update. Otherwise variables would be pretty... useless.
You are correct :) I did not know that :) But I was able to hack it by setting the animation as a string: foo.style.animation = "my-animation 2s forwards" and then keeping the actual keyframe animation in the stylesheet: jsfiddle.net/3roed9qv
--foo-baras a property name can not work in this syntax - you'd have to put it in quotes. Not sure if you will be able to directly animate this then though - you might need to declare your variable as a custom property first, stackoverflow.com/a/64333786/1427878foo.style.animation = "my-animation 2s forwards"and then keeping the actual keyframe animation in the stylesheet: jsfiddle.net/3roed9qv