react-smooth-slider
Version:
39 lines (32 loc) • 808 B
JavaScript
export default class {
start = { x: 0, y: 0 };
end = { x: 0, y: 0 };
touches = 0;
isScrolling = false;
swiped = false;
getAverage = (touches, axis) => (
Array.from(touches).reduce((prev, cur) => prev + cur[`client${axis}`], 0) / touches.length
)
onTouchEnd = () => {
this.isScrolling = false;
this.start = { x: 0, y: 0 };
this.end = { x: 0, y: 0 };
}
onTouchMove = (e) => {
this.touches = e.touches.length;
this.end = {
x: this.getAverage(e.touches, 'X'),
y: this.getAverage(e.touches, 'Y'),
};
if (!this.swiped) {
this.swiped = true;
}
if (!this.isScrolling) {
this.isScrolling = true;
this.start = {
x: this.getAverage(e.touches, 'X'),
y: this.getAverage(e.touches, 'Y'),
};
}
};
}