1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-08-21 12:21:46 +02:00

Adding scroll to plugin

This commit is contained in:
Antonio Laguna
2017-01-30 15:47:17 +01:00
parent ff3c2d066a
commit c5133158ad
3 changed files with 52 additions and 2 deletions

View File

@@ -185,7 +185,7 @@ export default class WebSlides {
}
DOM.unlockScroll();
callback.call(this, nextSlide);
setTimeout(() => { callback.call(this, nextSlide); }, 150);
});
}

View File

@@ -0,0 +1,50 @@
import ScrollHelper from '../utils/scroll-to';
const MIN_WHEEL_DELTA = 40;
export default class Scroll {
/**
* Scroll handler for the WebSlides.
* @param {WebSlides} wsInstance The WebSlides instance
*/
constructor(wsInstance) {
/**
* @type {WebSlides}
* @private
*/
this.ws_ = wsInstance;
this.scrollContainer_ = ScrollHelper.getScrollableContainer();
this.isGoingUp_ = false;
if (this.ws_.isVertical) {
this.scrollContainer_.addEventListener(
'wheel', this.onMouseWheel_.bind(this));
}
}
/**
* Reacts to the wheel event. Detects whether is going up or down and decides
* if it needs to move the slide based on the amount of delta.
* @param {WheelEvent} event The Wheel Event.
* @private
*/
onMouseWheel_(event) {
if (this.ws_.isMoving) {
return;
}
const { deltaY: wheelDelta } = event;
this.isGoingUp_ = wheelDelta < 0;
if (Math.abs(wheelDelta) >= MIN_WHEEL_DELTA) {
if (this.isGoingUp_) {
this.ws_.goPrev();
} else {
this.ws_.goNext();
}
event.preventDefault();
}
}
};

View File

@@ -1,6 +1,6 @@
import Easings from './easing';
let SCROLLABLE_CONTAINER;
let SCROLLABLE_CONTAINER = getScrollableContainer();
/**
* Returns the correct DOM element to be used for scrolling the