fix event listener to work with with animation frame