src/components/ebay-carousel/index.js
function handleScroll(scrollLeft) {
    const { state } = this;
    const { config, items, gap } = state;
    let closest;

    if (scrollLeft >= getMaxOffset(state) - gap) {
        closest = items.length - 1;
    } else {
        // Find the closest item using a binary search on each carousel slide.
        const itemsPerSlide = state.itemsPerSlide || 1;
        const totalItems = items.length;
        let low = 0;
        let high = Math.ceil(totalItems / itemsPerSlide) - 1;

        while (high - low > 1) {
            const mid = Math.floor((low + high) / 2);
            if (scrollLeft > items[mid * itemsPerSlide].left) {
                low = mid;
            } else {
                high = mid;
            }
        }

        const deltaLow = Math.abs(scrollLeft - items[low * itemsPerSlide].left);
        const deltaHigh = Math.abs(scrollLeft - items[high * itemsPerSlide].left);
        closest = normalizeIndex(state, (deltaLow > deltaHigh ? high : low) * itemsPerSlide);
    }

    if (state.index !== closest) {
        config.skipScrolling = true;
        config.preserveItems = true;
        this.setState('index', closest);
        emitAndFire(this, 'carousel-scroll', { index: closest });
    }
}
function handleScroll(scrollLeft) {
    const { state } = this;
    const { config, items, gap } = state;
    let closest;

    if (scrollLeft >= getMaxOffset(state) - gap) {
        closest = items.length - 1;
    } else {
        // Find the closest item using a binary search on each carousel slide.
        const itemsPerSlide = state.itemsPerSlide || 1;
        const totalItems = items.length;
        let low = 0;
        let high = Math.ceil(totalItems / itemsPerSlide) - 1;

        while (high - low > 1) {
            const mid = Math.floor((low + high) / 2);
            if (scrollLeft > items[mid * itemsPerSlide].left) {
                low = mid;
            } else {
                high = mid;
            }
        }

        const deltaLow = Math.abs(scrollLeft - items[low * itemsPerSlide].left);
        const deltaHigh = Math.abs(scrollLeft - items[high * itemsPerSlide].left);
        closest = normalizeIndex(state, (deltaLow > deltaHigh ? high : low) * itemsPerSlide);
    }

    if (state.index !== closest) {
        config.skipScrolling = true;
        config.preserveItems = true;
        this.setState('index', closest);
        emitAndFire(this, 'carousel-scroll', { index: closest });
    }
}
function handleScroll ( scrollLeft ) { const { state } = this ; const { config , items , gap } = state ; let closest ; if ( scrollLeft >= getMaxOffset ( state ) - gap ) { closest = items . length - 1 ; } else { // Find the closest item using a binary search on each carousel slide. const itemsPerSlide = state . itemsPerSlide || 1 ; const totalItems = items . length ; let low = 0 ; let high = Math . ceil ( totalItems / itemsPerSlide ) - 1 ; while ( high - low > 1 ) { const mid = Math . floor ( ( low + high ) / 2 ) ; if ( scrollLeft > items [ mid * itemsPerSlide ] . left ) { low = mid ; } else { high = mid ; } } const deltaLow = Math . abs ( scrollLeft - items [ low * itemsPerSlide ] . left ) ; const deltaHigh = Math . abs ( scrollLeft - items [ high * itemsPerSlide ] . left ) ; closest = normalizeIndex ( state , ( deltaLow > deltaHigh ? high : low ) * itemsPerSlide ) ; } if ( state . index !== closest ) { config . skipScrolling = true ; config . preserveItems = true ; this . setState ( 'index' , closest ) ; emitAndFire ( this , 'carousel-scroll' , { index : closest } ) ; } }
Find the closest item index to the scroll offset and triggers an update.

@param {number} scrollLeft The current scroll position of the carousel.
Find the closest item index to the scroll offset and triggers an update .