May 2017
Intermediate to advanced
448 pages
10h 10m
English
The throttling technique we've implemented is efficient and simple, but it is not the only solution. Depending on the performance characteristics of the action being throttled and typical interaction with the page, we may, for instance, want to institute a single timer for the page rather than create one when an event begins:
$(() => { var scrolled = false; $(window) .scroll(() => { scrolled = true; }); setInterval(() => { if (scrolled) { checkScrollPosition(); scrolled = false; } }, 250); checkScrollPosition();});
Unlike our previous throttling code, this polling solution uses a single call to the JavaScript setInterval() function to begin checking the state of the scrolled variable every ...
Read now
Unlock full access