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

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -