I can't figured out how to move the boxes back and forth
.
I can move from left to right
, but if i try from right to left
it goes crazy.
Here you have the code
Here you have the live example
The problem was the output of the box.style.transform.replace(/[^\d]/g, '')
.
It returned the only the positive number e.g: 100px
even if the property value is: translateX(-100px)
.
The solution was to get the negative value aswell. All i need to do was to change the regex statement
.
SOLUTION: box.style.transform.replace(/[^-\d]/g, '')
.
EXPLANATION: Replace all characters that are NOT -
or number / digit
.
Code and live example updated.