简体   繁体   English

CSS3-分步在屏幕上翻译元素吗?

[英]CSS3 - Translating an element across the screen in steps?

I need to translate an element across the screen in steps of say 50px. 我需要在屏幕上以50px的步长转换元素。 Upon every click, the element moves 50px to the right, lets say. 假设每次点击时,元素都会向右移动50px。

How do i correct the following code? 如何更正以下代码?

http://jsfiddle.net/vujMV/13/ http://jsfiddle.net/vujMV/13/

Here it jumps 50px each time and then translates 50px, a total of 100px per click. 在这里,它每次跳50px,然后转换50px,每次点击总计100px。 I need the movement to be hardware accelerated (since it is to be deployed on a mobile platform) and hence I would need to use translate(). 我需要对移动进行硬件加速(因为它将被部署在移动平台上),因此我将需要使用translate()。

Just comment out the final two lines. 只需注释掉最后两行。 Those are what cause the initial 50px jump: 这些是导致初始50px跳变的原因:

//left += 50;
//move.style.left = left+"px";

Edit 编辑
To make it work each time you click it, you need to change the translate3d property relative to the current one, rather than the .offset property since that is no longer changing once you comment out the above lines. 为了使它每次单击都可以工作,您需要相对于当前属性更改translate3d属性,而不是.offset属性,因为一旦注释掉上述各行,该属性就不再更改。

Here's a working example: http://jsfiddle.net/vujMV/16/ 这是一个工作示例: http : //jsfiddle.net/vujMV/16/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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