简体   繁体   English

动画性能问题velocity.js

[英]Animation performance issue velocity.js

I'm trying to animate spans and the animation seems to be working but it is a bit laggy and not smooth. 我正在尝试为跨度设置动画,并且动画似乎可以正常运行,但是有点滞后且不流畅。

https://codepen.io/pokepim/pen/JBRoay I think it is because im using left/right to animate https://codepen.io/pokepim/pen/JBRoay我认为这是因为即时通讯使用左/右进行动画处理

$(".bf").velocity({left: "100%" })
$(".af").velocity({right: "100%" })

Now im trying to reconstruct this behaviour using translateX but it doesnt work as intended (actually it does not animate at all) 现在我正在尝试使用translateX重建此行为,但是它没有按预期工作(实际上它根本没有动画)

$(".bf").velocity({ translateX: "-100%" })
$(".af").velocity({ translateX: "100%" })

This is codepen for this example 这个例子是codepen

https://codepen.io/pokepim/pen/ejzZvy https://codepen.io/pokepim/pen/ejzZvy

You are using Velocity V2, which does not have the broken fake transformX style shortcuts in it. 您正在使用Velocity V2,它没有损坏的假的transformX样式快捷方式。 The top of the github page states clearly that the documentation on the website refers to V1 only, and to refer to the Github wiki for V2 documentation. github页面顶部清楚地表明,该网站上的文档仅引用V1,并引用Github Wiki中的V2文档。

Just use real css for animation, and that means using the real transform property. 只需将真实的CSS用作动画,就意味着使用真实的transform属性。 The safest way to do this is via forcefeeding the first time you animate it as it cannot read the value from the browser (there are reasons mentioned in the wiki): 最安全的方法是在首次设置动画时通过强制进给,因为它无法从浏览器中读取值(Wiki中提到了一些原因):

$(".bf").velocity({ transform: ["translateX(-100%)", "translateX(0%)"] }); $(".af").velocity({ transform: ["translateX(100%)", "translateX(0%)"] });

Of further note, Velocity has absolutely nothing to do with jQuery now, so if all you are doing is selecting elements, it is quite safe to drop jQuery and use the built-in methods instead: 需要进一步注意的是,Velocity现在与jQuery完全无关,因此,如果您要做的只是选择元素,则删除jQuery并使用内置方法是相当安全的:

document.querySelectorAll(".bf").velocity({ transform: ["translateX(-100%)", "translateX(0%)"] }); document.querySelectorAll(".af").velocity({ transform: ["translateX(100%)", "translateX(0%)"] });

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

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