Skip to content

Instantly share code, notes, and snippets.

@tarun-dugar
Last active May 5, 2019 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarun-dugar/7ed0983df9a55609525e19d845aaee4d to your computer and use it in GitHub Desktop.
Save tarun-dugar/7ed0983df9a55609525e19d845aaee4d to your computer and use it in GitHub Desktop.
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