9

I am just trying to understand why the hell window.requestAnimationFrame is accepting the second parameter as an element, what is the reason behind that?

I am curious to know the underlying execution for this function....

Software Enthusiastic
  • 25,147
  • 16
  • 58
  • 68
  • Interestingly TypeScript (0.9.1) complains if this argument is not provided. I wonder if there's a good reason for that. It seems to work fine (in Chrome at least) without it. – Drew Noakes Jul 13 '13 at 21:03

1 Answers1

14

It's added so that when an element is out of view (because of scrolling for example), the animation is not run.

From the specs:

Editorial note

ISSUE-4 Do we want to allow an Element to be passed to requestAnimationFrame, so that animations affecting the given element are throttled or paused when scrolled out of view?

More information about this issue can be found here.

Community
  • 1
  • 1
pimvdb
  • 151,816
  • 78
  • 307
  • 352