Created
October 16, 2017 06:13
-
-
Save akccakcctw/ff9671d6a7742a044eda54c5cd8aea5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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