Jquery animated image(script)

1 points by graham_holborn ↗ HN
I built this on my lunch break for no good reason.

you can turn any image into a animated image with this.

animatedData = [ 50,//FRAME WIDTH (width of each video frame)

50,//FRAME HIGHT (height of each video frame)

200,//IMAGE WIDTH (image file width)

200,//IMAGE HEIGHT (image file height)

100,//SPEED in MS (FPS = (MS/10))

'animated-image'// DOM ID (DOM Element ID) ];

window.animateImgGrid = [0,0,

((animatedData[2]/animatedData[0])-1),

((animatedData[3]/animatedData[1])-1)];

function animateImg(animatedData);

function animateImg(array){ $('#' + array[5]).css({'background-position':'' + (window.animateImgGrid[0] * array[0]) + 'px ' + (window.animateImgGrid[1] * array[1]) + 'px'}); if(window.animateImgGrid[0] >= window.animateImgGrid[2] && window.animateImgGrid[1] >= window.animateImgGrid[3]){ window.animateImgGrid[1] = 0; window.animateImgGrid[0] = 0; } else if(window.animateImgGrid[0] >= window.animateImgGrid[2]){ window.animateImgGrid[1]++; window.animateImgGrid[0] = 0; } else{ window.animateImgGrid[0]++; } window.t=setTimeout(function(){animateImg(array);},array[4]); }

0 comments

[ 4.7 ms ] story [ 15.5 ms ] thread

No comments yet.