I’m using jQuery.crSpline to animate a graphic along a curved path. I’m pretty happy with the result.
However, the full canvas size is intentionally pretty wide – definitely larger than most screens – so the graphic will run out of viewport space pretty quickly and animate off the screen.
Instead, I’d like browser viewport to follow or centre on the image so that it stays ‘in shot’.
How would I go about this with jQuery? Is scrollTop an option?
I’ve created a jsFiddle demo, based on the crSpline demo source, but with a wide minX setting.
NB: I did first attempt this with YUI3 and Loktar offered a canvas based solution, however I’m not using YUI & canvas any longer.
There exists an option for
stepfunction in jQuery animate,which is run on every step of the animation.See second version of function parameters here :
http://api.jquery.com/animate/
See this fiddle based on your code, which calls
stepfunction to adjust viewport :http://jsfiddle.net/gNdwD/35/