root.style.setProperty('--services-box-delay-"+ i +"', totalServicesLines + "s");
This is seemingly so simple, but I can’t get it to work due to (probably) variable escaping wrong understanding.
I have two variables here: i and totalServicesLines.
What is wrong here?
2
Answers
Looks weird, but on base of what Mohammed suggested this one works:
Do like this and I think it will work:
Example:
If i = 1 and totalServicesLines = 3
With your code, you will get
root.style.setProperty('--services-box-delay-"i"', "3s");
The variable i will not be evaluated.
Instead, if you add " before and after i, it will be like this:
root.style.setProperty('--services-box-delay-1', "3s");
.And these are js and not css variables.
The css property that you’re trying to chabge is –services-box-delay-"1" which will get "3s" as value.