-
-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Idea/v9] Slow down scrolling on hitting Upper and Lower Page End #408
Labels
Milestone
Comments
//& Edge Damping Plugin for Smooth Scrollbar
import Scrollbar from "smooth-scrollbar";
class EdgeDamping extends Scrollbar.ScrollbarPlugin {
transformDelta(delta, fromEvent) {
const dirX = delta.x > 0 ? 1 : -1;
const dirY = delta.y > 0 ? 1 : -1;
if (dirX === this.lockX || dirY === this.lockY) {
return { x: 0, y: 0 };
} else {
this.lockX = null;
this.lockY = null;
}
return delta;
}
onRender(Data2d) {
const { x, y } = Data2d;
//@ Scroll Up
if (y < 0 && !this.lockY && Math.abs(y) >= this.scrollbar.scrollTop) {
this.scrollbar.setMomentum(0, -this.scrollbar.scrollTop);
this.lockY = -1;
}
//@ Scroll Left
if (x < 0 && !this.lockX && Math.abs(x) >= this.scrollbar.scrollLeft) {
this.scrollbar.setMomentum(-this.scrollbar.scrollLeft, 0);
this.lockX = -1;
}
//@ Scroll Right
if (
x > 0 &&
!this.lockX &&
Math.abs(x) >= this.scrollbar.limit.x - this.scrollbar.scrollLeft
) {
this.scrollbar.setMomentum(
this.scrollbar.limit.x - this.scrollbar.scrollLeft,
0
);
this.lockX = 1;
}
//@ Scroll Down
if (
y > 0 &&
!this.lockY &&
Math.abs(y) >= this.scrollbar.limit.y - this.scrollbar.scrollTop
) {
this.scrollbar.setMomentum(
0,
this.scrollbar.limit.y - this.scrollbar.scrollTop
);
this.lockY = 1;
}
if (y === 0) this.lockY = null;
if (x === 0) this.lockX = null;
}
}
//& Register Plugin name and Export Class
EdgeDamping.pluginName = "EdgeDamping";
export default EdgeDamping; Just use this Plugin |
@idiotWu It would be nice if the plugin was included in the official package. The plugin works great on all projects (over 20+) that i have implemented.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussed in #398
Originally posted by blitzve0 October 31, 2021
Currently when we keep scrolling and reach the end of the page or top of the page, the page abruptly stops on hitting the end. If the scroller would slow down and smooth out when hitting the edges the experience would be much more impressive
The text was updated successfully, but these errors were encountered: