用javascript移动元素 [英] Moving elements with javascript

查看:101
本文介绍了用javascript移动元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用javascript移动元素的最佳做法是什么?
您是否使用超时或间隔?
定时事件持续10毫秒是否不好,还是精确?
您是否逐像素地移动像素,还是移动总距离的一定比例?
如果你使用间隔时间,当元素到位时如何停止间隔?

我在javascript中看到动作的最后两次是与jQuery和Raphael.js,我都不能理解的源代码。有没有一些很好的教程或代码示例在任何地方?有没有简单的解释jQuery使用的方法?

解决方案

在这里你可以找到一个好的Javascript动画教程:
http://www.schillmania.com/content/projects/javascript-animation-1



但是你说的是对的。 Jquery Animate使用setTimeout,根据计算持续时间,位置和缓动来移动对象。


What are the best practices for moving elements with javascript? Do you use timeouts or intervals? Is it bad to have timed events for 10 milliseconds, or will it be precise? Do you move pixel by pixel, or a certain fraction of the total distance? If you use intervals, how do you stop the interval when the element is in position?

The last two times I've seen motion in javascript have been with jQuery and Raphael.js, neither of which I can understand the source code of. Are there some good tutorials or code examples anywhere? Is there a simple explanation of the methods jQuery uses?

解决方案

Here you can find a good Javascript Animation tutorial: http://www.schillmania.com/content/projects/javascript-animation-1

But what you said is right. Jquery Animate uses setTimeout, moving the object based in calculations of duration, position and easing.

这篇关于用javascript移动元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆