最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to create a smooth animation that eases toward the target - Stack Overflow

programmeradmin0浏览0评论

How can I create a smooth animation that eases in toward a target as it changes position?

As this jsFiddle shows, the animation stops or gets blocked during moveTarget() instead of continuing toward the new target coordinates.

What would be the ideal implementation / structure to achieve the desired effect?

How can I create a smooth animation that eases in toward a target as it changes position?

As this jsFiddle shows, the animation stops or gets blocked during moveTarget() instead of continuing toward the new target coordinates.

What would be the ideal implementation / structure to achieve the desired effect?

Share Improve this question asked Feb 15, 2012 at 22:00 Danny GarciaDanny Garcia 8412 gold badges9 silver badges24 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Ok, answering my own question here in case anyone else has this problem.

Instead of calculating change (change = finish - begin) each time moveTarget() fires, it is constantly being calculated in onEnterFrame(). So moveTarget() only responsible for getting the new X and Y positions.

This allows the values to ease toward the target.

I also permanently set the time value of the easing function to always be 1:

easeIn(1, begin, change, duration);

The example answer is in this revision jsFiddle: http://jsfiddle/dannygarcia/LqP2R/45/

发布评论

评论列表(0)

  1. 暂无评论