-
Hi Team, i need an effect like this issue, but i can't write them in javascript browser. It always says " Cannot read properties of undefined (reading 'pluginName')". Can you help me with the code using javascript?, instead of typescript. I think a lot of people need this. Thank you author. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
You can check #104 (comment) to see how to write a plugin in es5 syntax. P.S. are you the one who sent me the email about the same question? |
Beta Was this translation helpful? Give feedback.
-
To be more specific: var Scrollbar = window.Scrollbar;
// see also: https://github.com/idiotWu/smooth-scrollbar/issues/198#issuecomment-496264237
function EdgeEasingPlugin() {
Scrollbar.ScrollbarPlugin.apply(this, arguments);
this._remainMomentum = {
x: 0,
y: 0,
};
}
EdgeEasingPlugin.prototype = Object.create(Scrollbar.ScrollbarPlugin.prototype);
EdgeEasingPlugin.prototype.transformDelta = function(delta) {
const {
limit,
offset,
} = this.scrollbar;
const x = this._remainMomentum.x + delta.x;
const y = this._remainMomentum.y + delta.y;
// clamps momentum within [-offset, limit - offset]
this.scrollbar.setMomentum(
Math.max(-offset.x, Math.min(x, limit.x - offset.x)),
Math.max(-offset.y, Math.min(y, limit.y - offset.y)),
);
return { x: 0, y: 0 };
}
EdgeEasingPlugin.prototype.onRender = function onRender(remainMomentum) {
Object.assign(this._remainMomentum, remainMomentum);
}
EdgeEasingPlugin.pluginName = 'edgeEasing'; |
Beta Was this translation helpful? Give feedback.
-
@idiotWu |
Beta Was this translation helpful? Give feedback.
-
Oh, Perfect.
|
Beta Was this translation helpful? Give feedback.
-
@idiotWu |
Beta Was this translation helpful? Give feedback.
To be more specific: