JavaScript - 平滑移动/调整大小 [英] JavaScript - Smooth Movement / Resizing
问题描述
如何在一段时间内实现对象的平滑调整大小或移动。我应该用小于像素的单位改变物体的位置吗?我目前正在使用setTimeout对其进行计时,有没有比setTimeout更有效的移动对象一段时间?
CSS 3动画可能会更快,因为它基于本地例程。除此之外... setTimeout
是你如何做到的。 尽管 setInterval
可能会让你更容易进行转换。
您可以查看一些 JavaScript动画库,并查看它们使用的具体技术。或者,您可以查看诸如从头开始的JavaScript动画等内容。或者John Resig的JavaScript忍者秘密的动画章节,当他释放它。 :)
How can I achieve smooth resizing or movement of an object over a period of time. Should I change the position of the object by units smaller than pixels? I am currently timing this using setTimeout, is there a more efficient way of moving an object over a period of time than setTimeout?
CSS 3 Animation would probably be faster for browsers that support it, as it's based on native routines.
Other than that... setTimeout
is how you do it. Though setInterval
is probably going to make it easier to make your transitions.
You might take a look at some of the javascript animation libraries and see what specific techniques they use. Or, you could look at stuff like JavaScript Animation From Scratch. Or the animation chapter in John Resig's Secrets of the JavaScript Ninja when he releases it. :)
这篇关于JavaScript - 平滑移动/调整大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!