I would like to check the value of a variable inside my requestAnimationFrame function. I implement this value on the scroll wheel event. It seems to work but when I check the value inside my RAF fonction, it's still set at its first value.
I wonder how can I properly set my this.deltaY value ? Thank you very much
class MyClass
{
constructor ()
{
this.deltaY = 0;
}
init ()
{
this.playRAF();
window.addEventListener('wheel', function(e) {
this.deltaY = e.deltaY;
console.log(this.deltaY);
// it returns a number
});
}
playRAF ()
{
this.leRaf = requestAnimationFrame(this.playRAF.bind(this));
console.log(this.deltaY);
// it returns 0 all the time despite the function above :(
}
}
//////
const foo = new MyClass();
foo.init();