[英]Javascript - move box from current position ( testimonial slider )
I can't figured out how to move the boxes back and forth
.我不知道如何
back and forth
移动这些盒子。
I can move from left to right
, but if i try from right to left
it goes crazy.我可以
left to right
移动,但如果我right to left
尝试,它会发疯。
Here you have the live example这里有活生生的例子
The problem was the output of the box.style.transform.replace(/[^\d]/g, '')
.问题是
box.style.transform.replace(/[^\d]/g, '')
的 output 。
It returned the only the positive number eg: 100px
even if the property value is: translateX(-100px)
.它返回唯一的正数,例如:
100px
,即使属性值为: translateX(-100px)
。
The solution was to get the negative value aswell.解决方案是也获得负值。 All i need to do was to change the
regex statement
.我需要做的就是更改
regex statement
。
SOLUTION: box.style.transform.replace(/[^-\d]/g, '')
.解决方案:
box.style.transform.replace(/[^-\d]/g, '')
。
EXPLANATION: Replace all characters that are NOT -
or number / digit
.解释:替换所有非
-
或number / digit
的字符。
Code and live example updated.代码和实时示例已更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.