admin管理员组文章数量:1326099
i want to use .animate function but i have some problems i want to change the 'left' value but i don't know the width of the item that i will move so if i sent to animate timer to 1000 and the width of my item is 100px that will be different if the width of my item is 500px and for the animate when it es near the end of it's target it bee faster, is there anyway to move my item without worrying about speed and timeout ?
i want to use .animate function but i have some problems i want to change the 'left' value but i don't know the width of the item that i will move so if i sent to animate timer to 1000 and the width of my item is 100px that will be different if the width of my item is 500px and for the animate when it es near the end of it's target it bee faster, is there anyway to move my item without worrying about speed and timeout ?
Share Improve this question edited Sep 22, 2014 at 5:24 trrrrrrm asked Feb 25, 2010 at 2:40 trrrrrrmtrrrrrrm 11.8k25 gold badges87 silver badges131 bronze badges3 Answers
Reset to default 6If I understand you correctly, you want to change the left of the item you are animating, but you want it to move at a constant speed, not plete in a constant time. In fact moving an item at a constant speed is the default way of animating in javascript (setInterval, setTimeout, etc.) JQuery is a shortcut for the people who don't want to do the tedious calculations involved in the (more frequent) case of wanting a transition to occur in constant time.
So, two ways you can do it. One: Don't use JQuery for that animation. Use setInterval or setTimeout with a Date difference check. Two: Use JQuery but calculate the width so you can reverse calculate the time duration. You can get the width of any JQuery object with .width()
. From this you can calculate the distance that needs to be traveled and divide that by the speed (pixels per second) you want to stay constant to get the time to plug into the JQuery animate function. Make sense?
If anyone lands on this post the JQuery function animate() has a property called linear. $().animate({''}, speed, linear) This will make the animate() function move at a constant speed.
This plugin does exactly what you're looking for: https://github./lukeshumard/supremation
本文标签: javascripthow to make constant animation using jqueryStack Overflow
版权声明:本文标题:javascript - how to make constant animation using jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742193031a2430565.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论