简体   繁体   English

Javascript - 从当前 position 移动盒子(推荐 slider)

[英]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 code这里有代码

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM