Skip to content

Instantly share code, notes, and snippets.

@akccakcctw
Created October 16, 2017 06:13
Show Gist options
  • Save akccakcctw/ff9671d6a7742a044eda54c5cd8aea5e to your computer and use it in GitHub Desktop.
Save akccakcctw/ff9671d6a7742a044eda54c5cd8aea5e to your computer and use it in GitHub Desktop.
/**
* A node in the DOM tree.
*
* @external Node
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node Node}
*/
/**
*
* @param {external:Node} el - Element want to scroll
* @param {number} to - The final scrollLeft value
* @param {number} duration - Duration time(ms)
*/
const timelineScrollTo = (el, to, duration) => {
if (duration <= 0) return;
const difference = to - el.scrollLeft;
const perTick = (difference / duration) * 2;
setTimeout(() => {
el.scrollLeft += perTick;
timelineScrollTo(el, to, duration - 2);
}, 10);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment