Replies: 1 comment 2 replies
-
|
You can add a helper function to scroll the container For example, const state = {
...
/**
* Scroll to target offset in range [0, 1].
* @param targetOffset Target offset value in [0, 1].
*/
scrollTo: (targetOffset: number) => {
if (el) {
const containerLength = size[horizontal ? 'width' : 'height'];
const scrollLength = el[horizontal ? 'scrollWidth' : 'scrollHeight'];
const scrollThreshold = scrollLength - containerLength;
const targetPixels = targetOffset * scrollThreshold; // Convert offset to pixel w.r.t the container
el.scrollTo({
top: horizontal ? 0 : targetPixels,
left: horizontal ? targetPixels : 0,
});
state.offset = targetOffset; // Set offset to target offset if you want to disable damping
}
},
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to scroll using a function instead of the mouse, similar to the window.scrollBy(x,y) function? This would be helpful when I want to scroll at a steady pace while recording a screen capture, for example. A useful implementation might be something like scrollBy(distance, duration) where the duration parameter could be a measure of time in ms.
Beta Was this translation helpful? Give feedback.
All reactions