Enhance scrolling performance by reducing expensive event listening

import throttle from 'lodash/throttle'; // Note: If leading and trailing options are true, func is invoked on the trailing edge of the timeout only if the throttled function is invoked more than once during the wait timeout. // Reference: https://lodash.com/docs#throttle window.addEventListener('scroll', throttle(callback, 1000, { leading: true, trailing: true }));

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.