From 1155a70f99f8ac30fdb41311191db7566f714dfb Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Tue, 21 Feb 2017 09:07:04 +0100 Subject: [PATCH] Meta: Fix scroll jank Debounce scroll events. Only update the DOM during requestAnimationFrame. Closes #314. --- index.bs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 5040a8d1..c83849d1 100644 --- a/index.bs +++ b/index.bs @@ -13108,6 +13108,7 @@ The following conformance classes are defined by this specification: options = options || {}; var OFFSET = 80, + needsUpdate = false, previous = null, current = null, currentNav = null, @@ -13124,7 +13125,15 @@ The following conformance classes are defined by this specification: return sections; }, []); - function onscroll(event) { + function onscroll() { + if (!needsUpdate) { + needsUpdate = true; + requestAnimationFrame(updatePosition); + } + } + + function updatePosition() { + needsUpdate = false; var scrollTop = (options.offset || 0) + getScrollTop(); current = sections.filter(function(section){ return section.offsetTop < scrollTop;