Skip to content

Instantly share code, notes, and snippets.

@tarun-dugar
Last active May 5, 2019 13:55
Embed
What would you like to do?
function smoothScroll(scrollParams) {
const elementToScroll = scrollParams.element;
const isWindow = elementToScroll === window;
const scrollDirectionProp = isWindow ? 'scrollX' : 'scrollLeft';
const elementWidthProp = isWindow ? 'innerWidth' : 'clientWidth';
const scrollLengthProp = 'scrollWidth';
const initialScrollPosition = elementToScroll[scrollDirectionProp];
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment