Skip to content

Instantly share code, notes, and snippets.

@molant
Last active December 14, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save molant/5127035 to your computer and use it in GitHub Desktop.
Save molant/5127035 to your computer and use it in GitHub Desktop.
How to process UI events with RAF
var deltaX = 0,
queued = false;
function myAction(){
//your awesome code here uses deltaX
deltaX = 0; //we reset the deltaX so it can be incremented next time onEvent is executed
queued = false;
}
function onEvent(evt){
if(!queued){
queued = true;
deltaX = evt.translationX; //in the case of a pointer, if you are using a mouse you will have to do some magic with pageX or similar :)
requestAnimationFrame(myAction);
}else{
deltaX += evt.translationX;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment