Translate not accepting variable

Here is a Video to explain it better.


I am trying to move a Div by binding a variable to the transform section in the builder.
It will work if I just use “translateX(-970px)” but when I use a variable “translateX(string-variable)” it doesnt work.
Ive tried several things but i am stuck at this point.

Can anyone help?
Thank you.

Hello, you need to use this special syntax I mentioned in my blog (one of them) or simply split the string and concatenate it with the + signs.

Thank you @Broberto thats very helpful but Im still not sure what im supposed to put there. Whatever I try doesnt seem to work.

variable widthNumber is a number “970”
Variable WidthForMultiStepForm is a string “970px”

Ive tried and doesnt work:

“translateX (“widthNumber”+“px”)”
“translateX (widthForMultiStepForm)” with and without “”
“translateX (${widthForMultiStepForm})”
“translateX ${widthForMultiStepForm}”
“translateX (${widthNumber”+“px”})"
“translateX ${“widthNumber”+“px”}”

Would you mind explaining where I am going wrong?

Try this:

“translateX(“ + [widthNumber] + “px)”

Which should follow the logic of:

"string" + [variable] + "string" - you need to use the concatenation pluses for both sides, think of it as a bike chain.

As for these ones, “translateX (${widthForMultiStepForm})” you almost got it right, but you need to use the special apostrophes as mentioned in the article to wrap your string.

That makes sense, but also does not work. :frowning:
I think I need to take a break and go to the gym. Im feeling stupid lol.

the translateX (${widthForMultiStepForm}) that works…with the backticks that dont show here, but thats a bit more confusing for me to work the math out with. the first one makes a lot more sense if I wanted to add or remove things.
This is helping though, thank you

1 Like

It probably doesn’t work because I saw that you already have the px there, so it would be translateX(100pxpx) these kinds of things indeed are solved faster in a video call. If you’d have some more complex issues, or just wanted to learn/understand something, I also do 1:1 coaching which works like a charm for these kind of “visual” cases.

there no px in the widthNumber, thats just a number. So “translateX(“ + [widthNumber] + “px)” should evaluate to 970px but it says “invalid or unexpected token”

Thanks for letting me know about the coaching. Ive been out of work since january. I was let go from blizzard along with 1900 others with no warning. So I’m not able to pay for anything until I find work or this app works out for me.

I think you might be doing something wrong, e.g. wrong quotes or something? Because it works on my end.

The only difference is Im not using spaces.

OMG :unamused: I unbound it, refreshed my page, put it in again. works fine.

thank you so much for your help

No worries! The formula editor is tricky indeed, but I heard it’s gonna get a revamp :eyes:

1 Like