jeudi 19 février 2015

requestAnimationFrame javascript alert increment jumps from 1 to 9 or 13


I've got this weird problem, I'm incrementing by 1, and yet, the increment that appears when the javascript window pops up, shows that I have incremented either by 9 or 13, the either comes from whether I am incrementing by 1 or -1 respectively. what is up with that?


This the function being called by the requestAnimationFrame



function stream1(){
if(y>origin_y){
var xOffset = -1;
}else if(y==origin_y){
var xOffset = 1;
}else {
var xOffset = 1;
}

var offset = $( "#widget1" ).offset();
var x = offset.left;
var y = offset.top;
console.log(' X - '+x+' Y - '+y);
$( "#widget1" ).offset({ top: y-yOffset, left: xInitial+xOffset });
}


This is the animation frame



var globalID;
function repeatOften() {
stream1();
requestAnimationFrame(repeatOften);
}


It probably doesn't make sense that in the time for the alert to disappear and reappear, 9 iterations have been complete right? It's supposed to be 60 times a second supposedly and it has been like 1 second so shouldn't it be 60 and not 9 or 13? I don't know where these arbitrary numbers come from.


To summarize again, initially xInitial is located at 1114 px, then it goes to 1105 or 1103 and then 9 or 13 gaps subsequentially every time so why is that?





Aucun commentaire:

Enregistrer un commentaire