performance issue with document.body.scrollTop and document.body.scrollLeft?

229 views
Skip to first unread message

Andre Baumeier

unread,
May 21, 2013, 10:49:43 PM5/21/13
to chromium...@chromium.org
I implemented a few functions responding on the scroll event, it seems like document.body.scrollTop and document.body.scrollLeft do not cache it's calls between scroll events. This leads to heavy performance difficulties if you dont cache it yourself. I dont see why this call is not cached or why it is so expensive?

You can easily see it attaching a scroll event listener to your page e.g. jQuery

jQuery(window).scroll(function() {
  // do stuff with document.body.scrollLeft and document.body.scrollTop
  document.body.scrollLeft;
  document.body.scrollTop;
  document.body.scrollLeft;
  document.body.scrollTop;
  document.body.scrollLeft;
  document.body.scrollTop;
  document.body.scrollLeft;
  document.body.scrollTop;
});

add those up and see your fps drop in timeline.

Reply all
Reply to author
Forward
0 new messages