javascript - using jQuery to switch background position every 250px -


im new jquery , not sure best way change background position, need change background position every 0 -250px, 0 -500px etc... know best way this?

cheers

js:

function startavataranimation() {      var avatarheight = 250;     var avatartotalheight = 2750;     var = 0;     var avatarspeed = 1000;      setinterval(function(){         i++;         if(i > avatararray.length){             = 0;         }         $(".avatars").css({'background-position' : '0 -' + (i*avatarheight) + 'px' });     }, avatarspeed);  } 

html:

<div class="avatars"></div> 

im getting error @ moment avatararray not defined, first attempt hope ok. guess needs work out height knows when stop well?

thanks again

fixed following solution:

function startavataranimation() {      var avatarheight = 250;     var avatartotalheight = 2750;     var = 0;     var avatarspeed = 500;     var avatararray = {};      setinterval(function(){         i++;         if(i > avatararray.length){             = 0;         }         $(".avatars").css({'background-position' : '0 -' + (i*avatarheight) + 'px' });     }, avatarspeed);  } 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -