Javascript - 从当前位置移动框(推荐滑块)

Javascript - move box from current position ( testimonial slider )

我不知道如何移动箱子 back and forth

我可以从 left to right 移动,但如果我尝试从 right to left 移动,它就会变得疯狂。

这里有 code

这里有 live example

问题是 box.style.transform.replace(/[^\d]/g, '') 的输出。

它仅返回正数,例如:100px,即使 属性 值为:translateX(-100px).

解决方案也是获得负值。我需要做的就是更改 regex statement.

解决方案:box.style.transform.replace(/[^-\d]/g, '').

说明:替换所有非 -number / digit.

的字符

Code and live example 已更新。