by simonw · 18y ago · 0 comments
Of course, you can roll that stuff yourself - but why duplicate all of that effort?
Also, DOM manipulation with the regular DOM is amazingly inconvenient when compared to manipulation using a library such as jQuery. The DOM is a pretty verbose API with a lot of weird quirks (removing a node: "theNode.parentNode.removeChild(theNode)") - jQuery provides a much more sensible API, which in turn means that I find myself using DOM manipulation a lot more since it isn't such a pain to do.
Just track the actual number of frames an animation has taken so far and the number of frames it needs to take to complete in the time taken. For bonus points re-average your framerate each time an animation ends by keeping track of the number of frames an animation actually was able to take.
And as far as easing goes...
eg
function timerMethod() { currentFrame = (currentTime - startTime) * numFrames / animationDuration; }
And to do 'easing' as you call it, you could just use sin/cos, or a small lookup table.
The main reason to duplicate effort is to firstly learn how these things work, and secondly to get a better solution matched more optimally to your use case.
I personally like the DOM... theNode.parentNode.removeChild(theNode) makes quite a lot of sense. But it's probably a matter of taste that one.