license const enum DeltaMode { DeltaPixel = 0 , DeltaLine = 1 , DeltaPage = 2 } export default class HorizontalMouseWheelMimic { private wheelEventFn : ( delta : number ) => void ; constructor ( private window , target , smooth ) { this . wheelEventFn = SmoothScroll ( target , smooth ) ; } onWheel ( ev , fontSize ) { if ( ! ev . deltaY || ev . deltaX || ev . altKey || ev . shiftKey || ev . ctrlKey || ev . metaKey ) { return ; } let scrollDistance ; switch ( ev . deltaMode ) { case DeltaMode . DeltaPixel : scrollDistance = ev . deltaY ; break ; case DeltaMode . DeltaLine : scrollDistance = ev . deltaY * fontSize * 1.75 ; break ; default : scrollDistance = ev . deltaY * this . window . innerWidth ; } this . wheelEventFn ( - scrollDistance ) ; ev . preventDefault ( ) ; } } function SmoothScroll ( target , smooth ) { const scrollAxis = 'scrollLeft' ; let moving = false ; let targetPos = target [ scrollAxis ] ; let expectedPos = target [ scrollAxis ] ; function update ( ) { moving = true ; const delta = Math . trunc ( ( targetPos - target [ scrollAxis ] ) / smooth ) ; if ( target [ scrollAxis ] !== expectedPos ) { moving = false ; } else { expectedPos += delta ; target . scrollBy ( delta , 0 ) ; if ( Math . abs ( delta ) > 0 ) { requestAnimationFrame ( update ) ; } else { moving = false ; } } } return ( delta ) => { if ( ! moving ) { targetPos = target [ scrollAxis ] ; expectedPos = target [ scrollAxis ] ; } targetPos += delta ; if ( ! moving ) { requestAnimationFrame ( update ) ; } } ; }