UNPKG

@ebay/ebayui-core

Version:

Collection of core eBay components; considered to be the building blocks for all composite structures, pages & apps.

30 lines (29 loc) 753 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.onScrollDebounced = onScrollDebounced; const eventOptions = { passive: true, }; function onScrollDebounced(el, cb) { let timeout; waitForScroll(); return cancel; function waitForScroll() { el.addEventListener("scroll", handleScroll, eventOptions); } function handleScroll() { cancelWaitForScroll(); timeout = setTimeout(finish, 640); } function finish() { cb(); waitForScroll(); } function cancelWaitForScroll() { el.removeEventListener("scroll", handleScroll, eventOptions); } function cancel() { cancelWaitForScroll(); clearTimeout(timeout); } }