We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
requestAnimationFrame
request animation frame
$ component install component/raf
Request the animation frame withraf(fn), cancel withraf.cancel(id).
raf(fn)
raf.cancel(id)
varx=0;vary=50;varcanvas=document.querySelector('canvas');varctx=canvas.getContext('2d');varraf=require('raf');functionanimate(){raf(animate);draw();}varprev=Date.now();functiondraw(){varcurr=Date.now();vardiff=curr-prev;varp=diff/16;ctx.clearRect(0,0,900,300);ctx.beginPath();ctx.globalAlpha=.5;ctx.arc(x,y,10,0,Math.PI*2,false);ctx.fill();x+=2;y+=Math.sin(x/20)*5;prev=curr;}animate();
MIT