简体   繁体   English

在CSS3翻译动画后获取元素的新位置?

[英]Get new position of an element after CSS3 translate animation?

I use a CSS3 translate animation to move an object by say 10px 我使用CSS3翻译动画来移动一个对象10px

@-webkit-keyframes move{
  0% {}
100% {
     -webkit-transform: translate(10px);
     }  
}

If initially the object was at left=10px, then it should now be at left=20px. 如果最初对象在左边= 10px,那么它现在应该在左边= 20px。 However when I do 但是,当我这样做

document.getElementById("obj").style.left

it returns to me the value 10px even after the animation. 即使在动画之后它也会返回10px的值。 How do I get the new value using javascript ? 如何使用javascript获取新值? Preferably an answer without jQuery or any other framework :) 最好没有jQuery或任何其他框架的答案:)

The left value is the same, as the element has been translated, not moved with absolute positioning. 左边的值是相同的,因为元素已被翻译,而不是使用绝对定位移动。

As an aside, this is why these are so efficient, as the browser can tell exactly what to repaint, so it can be easily hardware accelerated etc as the translation doesn't affect anything else on the page. 顺便说一句,这就是为什么它们如此高效,因为浏览器可以准确地分辨出要重新绘制的内容,因此它可以很容易地加速硬件等,因为翻译不会影响页面上的任何其他内容。

You can examine the transform matrix used internally by using WebKitCSSMatrix and then add it onto the existing offset, but you'll likely find it more straightforward to either examine why you need to do this, or to keep track manually (ie if you started at 10px, then translated by 15px, you are now at 25px.) 您可以使用WebKitCSSMatrix检查内部使用的转换矩阵,然后将其添加到现有偏移量上,但您可能会发现更直接地检查您需要执行此操作的原因,或者手动跟踪(即如果您是从10px,然后翻译15px,你现在是25px。)

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

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