-
Notifications
You must be signed in to change notification settings - Fork 74
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
Suggestion for useful methods #26
Comments
Hi @luruke, Thanks a lot for those suggestions! 👍 I implemented a few weeks ago the
I would love to see your extended class and how you implemented them. |
Hi @baptistebriel, I remember I tried with const debounce = require('lodash/debounce');
const EventEmitter = require('eventemitter3');
const Smooth = require('smooth-scrolling');
const Barba = require('barba.js');
class Scroll extends Smooth.default {
constructor(opt = {}) {
super(opt);
this.ee = new EventEmitter();
this.isLock = false;
this.bind();
}
bind() {
Barba.Dispatcher.on('transitionCompleted', () => {
this.resize();
});
window.addEventListener('resize', debounce(this.resize.bind(this), 100));
}
lock() {
this.isLock = true;
TweenLite.to(this.dom.scrollbar.el, 0.3, { xPercent: 100 });
}
unlock() {
this.isLock = false;
this.resize();
TweenLite.to(this.dom.scrollbar.el, 0.3, { xPercent: 0 });
}
forcePosition(pos) {
this.vars.current = pos;
this.vars.target = pos;
}
calc(e) {
if (this.isLock) {
return;
}
super.calc(e);
}
run() {
super.run();
if (this.vars.current !== this.oldCurrentPrecise) {
this.ee.emit('run', this.vars.current);
}
this.oldCurrentPrecise = this.vars.current;
const c = Math.round(this.vars.current);
if (c !== this.oldCurrent) {
this.ee.emit('scroll', this.vars.current);
}
this.oldCurrent = c;
}
resize() {
super.resize();
this.calc({
deltaX: 0,
deltaY: 0
});
this.ee.emit('scroll');
}
}
const myScroll = new Scroll({
native: false,
section: document.getElementById('barba-wrapper'),
vs: {
touchMultiplier: 3
}
});
if (!Modernizr.phantomjs) {
myScroll.init();
}
module.exports = myScroll; |
|
Hi there!
There could be some useful methods that could be implemented in my opinion:
.lock() and .unlock()
To temporary lock the scroll
.setPosition()
Set a scroll position without having the tweening
What about adding a simple event-system/dispatcher?
Could be useful to subscribe to events (scroll, resize...)
I was able to implement those thing easily, just extending the class.
Not sure but to me they look quite handful / generic, what do you think?
The text was updated successfully, but these errors were encountered: